error 9 - simple code
I was going to say that "This assumes that C:\something\workbook.xls" exists.
Then I changed the code to try to open it and report back if it fails. Ignore
that line in the original post.
Dave Peterson wrote:
Dim myPath as string
dim myFileName as string
dim wkbk as workbook
mypath = "C:\something\"
if right(mypath,1) < "\" then
mypath = mypath & "\"
end if
myfilename = "workbook.xls" '<-- don't include the path here!
set wkbk = nothing
on error resume next
set wkbk = workbooks(myfilename)
on error goto 0
if wkbk is nothing then
on error resume next
set wkbk = workbooks.open(filename:=mypath & myfilename)
on error goto 0
end if
if wkbk is nothing then
msgbox "Not open and can't find it!"
else
msgbox wkbk.fullname
end if
This assumes that C:\something\
PBcorn wrote:
to open a workbook if it is not already open:
dim path as string
path = " letter:\...\\workbook.xls"
If Workbooks(path).IsOpen = False Then
workbooks.open filename:=path
Gives subscript out of range. The solutions i found by searching the forum
are a bit long-winded - why doesn't the above work?
--
Dave Peterson
--
Dave Peterson
|