Click to See Complete Forum and Search --> : file path


leary
May 8th, 2001, 04:50 AM
I have tried to take the drive letter path(currently my CD drive) off the this file to run in order to not get a "path not found" error, but i get an error for "1004" "masterschedule.xls" could not be found. I also have same file(masterschedule.xls) located in the file from which the program runs,
but doesn't seem to find it. I'm sure I have something worded wrong in code below. have tried
"masterschedule.xls","\masterschedule.xls"
Would like it to read file with no path errors, since it will be run on computer at work.code below, any suggestions welcome.

Set m_objApp = GetObject(, "Excel.Application")
m_objApp.Workbooks.Open "m:masterschedule.xls"
Set m_objSheet = m_objApp.ActiveSheet

Cimperiali
May 8th, 2001, 05:06 AM
for example:
dim myPathName as string
myPathName="m:\masterschedule.xls"
if dir(myPathName)<>"" then 'file exists, path is correct
else
'find the right path
'ie: mypathname = inputbox "Insert disk:\path\filename.xls"
...
end if
m_objApp.Workbooks.Open myPathName


Special thanks to Lothar "the Great" Haensler, Tom Archer, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Cakkie
May 8th, 2001, 05:42 AM
The file will be searched for on the drive that Excel is installed. This is because excel will search it's own application folder when you do not specify the full path. If the file is in the same directory as your application, you can use the app.path property to get the full path:

' get path
dim strPath as string
strPath = app.path
' if the application is in a root directory (like c:\) the app.path ends with a \
' if it's not in a root (like c:\temp), the app.path ends without a \, so we need to add it
If right(strPath,1) = "\" then
strPath = strPath & "masterschedule.xls"
else
strPath = strPath & "\masterschedule.xls"
end if

' instanciate excel
set m_objApp = GetObject(, "Excel.Application")
' open the file
m_objApp.Workbooks.Open strPath
set m_objSheet = m_objApp.ActiveSheet



I hope this is what you mean...



Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

leary
May 8th, 2001, 03:55 PM
now how can i have program open file itself.
i have to have .xls open in order for VB to read it.