View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to test if an Excel spreadsheet exists in VBScript?

Dim sh as Excel.Worksheet
On Error Resume Next
set sh = xlApp.WorkSheets("Test").Select
On Error goto 0
if not sh is nothing then
sh.select
Else
msgbox "Test does not exist"
End if

--
Regards,
Tom Ogilvy

"JP" wrote in message
...
I'm trying to reference an Excel spreadsheet that may not exist at the

time
of the test, like this:
xlApp.WorkSheets("Test").Select
I would like to test if the "Test" sheet exist before selecting it. How to
do it in VBScript? I tried this:
IsObject(xlApp.WorkSheets("Test")), but it only worked if "Test" existed,

it
gave me an error when it didn't.
Thanks a bunch,
JP