Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with the Call Shell command

Status
Not open for further replies.

mike1971

MIS
Feb 12, 2003
13
GB
I'm having trouble opening my excel sheet via the call shell commang my code is pretty simple as follows but I can't seem to get access to recognise the folder.

This works but only because the target file does not sit in a folder. Any ideas??

Private Sub CmdOpenXlFile_Click()
On Error GoTo Errhndl

Dim stAppName As String

stAppName = "C:\Program Files\MSOFFICE\Excel\EXCEL.EXE C:\accesstest.xls"
Call Shell(stAppName, 1)

Exitcmd:
Exit Sub

Errhndl:
MsgBox err.Description
Resume ExitCmd

End Sub

 
If your folders have spaces in their names, you'll have to enclose the path in quotes. The simplest solution is to avoid spaces in folder and file names.
Otherwise use chr(34) & path/filename & chr(34)

Ken
 
First add a reference to the Microsoft Excel Object Library under Tools, References in the code window.

Then

Dim myExcel As New Excel.Application

myExcel.Visible = True
myExcel.Workbooks.Open "C:\accesstest.xls"


Good luck! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
You can do this
Call Shell("C:\Program Files\MSOFFICE\Excel\EXCEL.EXE "" C:\My Documents\accesstest.xls")

This should work even if you have a space in the My Documents folder name. First notice that there is a space between .EXE and " and no space between the two quote marks after the .EXE

Paul
 
Unfortunatly not using spaces is not a option, what do you mean by enclosing in quotes, is it as follows?

"C:\Program Files\MSOFFICE\Excel\EXCEL.EXE C:\"folder"\accesstest.xls"

thanks for the info..


 
Try this:
stAppName = "C:\Program Files\MSOFFICE\Excel\EXCEL.EXE " & chr(34) & "C:\accesstest.xls" & chr(34)

chr(34) is the ANSI for the quote character

Ken
 
Thanks heaps for all the info, but still can't get it to work, really seems to hate those folders. I think I'll try a new method.

 
For an alternative, have a look at my FAQ:faq705-1971

copy the code into a module, then call it with:

fHandleFile("C:\accesstest.xls",WIN_MAX) and it will open the file in Excel. It will work with spaces in the filename and everything. You don't even need to worry about where Excel is installed on the machine as the code does all the work for you.

hth

Ben ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top