I'm trying to open Excel-sheet via VBA in Access 2003

  • Thread starter Thread starter hanski
  • Start date Start date
H

hanski

hi.

I have code:

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE
c:\documents and settings\forsale\houses.xls"
Call Shell(stAppName, 1)


But when I execute it comes a message: "you can't find 'c:
\documents.xls' etc.

I understand it do not accept space between the name but how can I
change it?


hanski
 
The problem is because you've got spaces in the path. You could solve it by
using

stAppName = """C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE""
""c:\documents and settings\forsale\houses.xls"""

(three double quotes at the beginning and end of the string, two pairs of
double quotes, separated by a space, in the middle)

However, I think you'll find the following is better because it doesn't
require you to know the location of Excel.exe (which means it will work for
anyone who has any version of Excel installed)

stSheet = "c:\documents and settings\forsale\houses.xls"
Application.FollowHyperlink stSheet
 
The problem is because you've got spaces in the path. You could solve it by
using

  stAppName = """C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE""
""c:\documents and settings\forsale\houses.xls"""

(three double quotes at the beginning and end of the string, two pairs of
double quotes, separated by a space, in the middle)

However, I think you'll find the following is better because it doesn't
require you to know the location of Excel.exe (which means it will work for
anyone who has any version of Excel installed)

  stSheet = "c:\documents and settings\forsale\houses.xls"
  Application.FollowHyperlink stSheet

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)












- Näytä siteerattu teksti -

Thanks a million lot Douglas!! Your idea was great and now it works!

hanski
 
Back
Top