Opening a excel woorkbook from VBA

R

reachkars

Hii...

My VBA code generates a new excel sheet based on a existing excel
template and saves the new excel sheet in a location desired by the
user.

The path where the excel sheet in saved is contained in the variable
"fName"

Now,

i try to open the excel application directly using,

Shell "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE " & FName,
vbMaximizedFocus

As long as the location is c:\xxx.xls or C:\test\xxx.xls (i.e) without
any spaces.. i dont have any problems.

But when the user saves it in his "my documents", the FName would be,

"C:\Documents and Settings\user\Desktop\xxx.xls"

now, it considers C:\Documents.xls as seperate path, and.xls as a
seperate path and Settings\user\Desktop\xxx.xls as a seperate path.

how do i resolve this....???
 
H

Helmut Weber

Hi,

try:

fname = "C:\Documents and Settings\user\Desktop\xxx.xls"
fname = chr(34) & fname & chr(34)

--
Greetings from Bavaria, Germany

Helmut Weber

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

reachkars

Thanks for your inputs...

Actually,i get the file name from the user and the save as location
from the user using..

FName = xlApp.Application.GetSaveAsFilename(sFileName & Format(date,
"yyyymmdd") & "_" & Format _
(Time, "hh.mm.ss") & ".xls", "Excel Workbook (*.xls), *.xls", ,
"Please choose the location to save the report")

If FName = False Then
MsgBox "Please choose a valid location to save the report"
GoTo Retry
End If

It is in this place where the user gets the option to choose, where to
save the excel.. if he chooses to save it in his desktop.. then the
problem i had mentioned earlier araises..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top