Open a specific excel file using runapp function

wongwm

New member
Local time
Today, 17:43
Joined
Sep 16, 2009
Messages
4
hi i have a problem whtn i trying to use runapp function to open a specific excel file, the problem is the path name of the folder

e.g. when i tried

Dim stAppName As String
stAppName = "excel.exe D:\POLICYTABLE.xls"
Call Shell(stAppName, 1)

it got no problem and open the file

but when i changed to

Dim stAppName As String
stAppName = "excel.exe D:\stAppName = "excel.exe D:\ABC folder\NEW Project\POLICYTABLE.xls"
Call Shell(stAppName, 1)

it cannot open the file and i think the space between ABC and folder, NEW and Project are causing the problem. anyone got any ideas that i can solve this problem ?:confused:

thanks.
 
Re: Open a specific excel file suing runapp function

Shouldn't

Code:
stAppName = "excel.exe D:\stAppName = "excel.exe D:\ABC folder\NEW Project\POLICYTABLE.xls"

Be

Code:
stAppName = "excel.exe D:\ABC folder\New Project\POLICYTABLE.xls"

I have spaces in my file path too and it works for me
 
Re: Open a specific excel file suing runapp function

sorry, i pasted wrongly, it should be

Dim stAppName As String
stAppName = "excel.exe D:\ABC folder\NEW Project\POLICYTABLE.xls"
Call Shell(stAppName, 1)


really? you can work even there is space between words in the path ?
 
Re: Open a specific excel file suing runapp function

Yeah it works fine with spaces between words in the file path.

I don't open directly from VB. I have a macro that opens the file and I call that macro from VB.
i.e. Macro Name = ProgressStatsExport
Action = RunApp
Command Line = C:\Program Files\Microsoft OfficeXP\Office10\excel.exe "K:\Rapid\BST - general\Release Testing\Testing Database\Progress Stats Template.xls"

And I call the macro using

Code:
Dim stDocName As String
 
stDocName = "ProgressStatsExport"
DoCmd.RunMacro stDocName
 
Re: Open a specific excel file suing runapp function

thanks ! it's working now...:D
 
Re: Open a specific excel file suing runapp function

Glad to be of service
 
Re: Open a specific excel file suing runapp function

Yeah it works fine with spaces between words in the file path.

I don't open directly from VB. I have a macro that opens the file and I call that macro from VB.
i.e. Macro Name = ProgressStatsExport
Action = RunApp
Command Line = C:\Program Files\Microsoft OfficeXP\Office10\excel.exe "K:\Rapid\BST - general\Release Testing\Testing Database\Progress Stats Template.xls"

And I call the macro using

Code:
Dim stDocName As String
 
stDocName = "ProgressStatsExport"
DoCmd.RunMacro stDocName

When I try to build a macro like this,
Command Line = C:\Program Files\Microsoft Office\Office12\EXCEL.exe "C:\Documents and Settings\Tai\My Documents\Downloads\Final Project\Final Project\MACROBUILD.xls"
I get a syntax error saying Access can't parse the expression. I can get past the syntax error by moving the quotation marks like so:
Command Line = "C:\Program Files\Microsoft Office\Office12\EXCEL.exe C:\Documents and Settings\Tai\My Documents\Downloads\Final Project\Final Project\MACROBUILD.xls"
However when I run it, I successfully open Excel, but then get error messages that the file "C:\Documents.xlsx" cannot be found, the file "and.xlsx" cannot be found, the file "Settings\Tai\My.xlsx" cannot be found, etcetera. It appears that the spaces are causing a problem. Any ideas on where the error is?
 
Don't hassle with the Shell. Just use this:

Code:
Dim xlApp As Object
Dim strFile As String

strFile="C:\Documents and Settings\Tai\My Documents\Downloads\Final Project\Final Project\MACROBUILD.xls"

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open(strFile)

xlApp.UserControl = True
Set xlApp = Nothing

Then you don't need to know which version is installed, what the path to the executable is, etc.
 

Users who are viewing this thread

Back
Top Bottom