View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Excel automation: connecting to Excel

If there are open workbooks, but all are hidden (no active sheet), then won't
both have trouble.

set moexcelws = nothing
on error resume next
Set moExcelWS = moExcelApp.ActiveWorkbook.ActiveSheet
on error goto 0

if moexcelws is nothing then
'failed
else
'worked
end if



Jack wrote:

Which one is better (safer) way to do:

1.
If moExcelApp.Workbooks.Count 0 Then 'when any sheet is opened
Set moExcelWS = moExcelApp.ActiveWorkbook.ActiveSheet
End if

or

2.
If moExcelApp.Workbooks.Count 0 Then 'when any sheet is opened
Set moExcelWS = moExcelApp.moExcelApp.Workbooks(1).Worksheets(1)
End if

Jack


--

Dave Peterson