Open file in VBA

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

Hello,

When I walk through the following statement I get a run time error 1004
that says that the particular file couls not be found.

I used the following statement:

sFilename = Dir("H:\Risk_Management\Special_Review\Upload_files\*.xls")
Workbooks.Open Filename:=sFilename

Do I forgot something?

Thanks for your assistance!!

Rgds,
Robert
 
Hi Robert,

dim sFilename as string
sFilename = Dir("H:\Risk_Management\Special_Review\Upload_files\*.xls")
if len(sfilename)<>0 then
Workbooks.Open Filename:=sFilename
else
'no file path returned from
dir("H:\Risk_Management\Special_Review\Upload_files\*.xls")
end if

Regads,
Ivan
 
Another possibility:
Dir doesn't return the path in sFileName, so

Dim sPath as String, sFileName as String
sPath = "H:\Risk_Management\Special_Review\Upload_files\"
sFileName = Dir(sPath & "*.xls")
if sFileName <> "" then
workbooks.Open Filename:=sPath & sFileName
Else
msgbox "No excel workbooks"
End if

--
Regards,
Tom Ogilvy


*.xls")
Workbooks.Open Filename:=sFilename
 

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

Similar Threads


Back
Top