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

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
 
D

Douglas J. Steele

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
 
H

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

--
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
 

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