View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Check for file before opening

Simon,
Why not attempt to open and trap the error.
Errors are not inherently bad; they provide you with information.
Dim WB As workbook
On Error Resume Next
Set WB=workbooks.open(PathToYourMaybeFile)
on error goto 0
If WB is nothing then
Set WB=workbooks.add
'Or whatever creation code you need
End if

NickHK

"simonhall" wrote
in message ...

Hi,

I need excel to open another excel file (workbook) as part of a macro.
How do I checkt the presence of the file before I try to open it so I
don't generate an error if the file is not there. If the file does not
exist, I will then create it, which I can do.

Thanks, Simon


--
simonhall
------------------------------------------------------------------------
simonhall's Profile:

http://www.excelforum.com/member.php...o&userid=30582
View this thread: http://www.excelforum.com/showthread...hreadid=561328