Test to see if a spreadsheet window is open

  • Thread starter Thread starter lopsided
  • Start date Start date
L

lopsided

Dear all,

Part of my macro calls a cell value on one sheet to switch between open
windows. If the value is not typed in correctly on the first sheet then
the macro gives the error "subscript out of range", and is unable to
open the other sheet.

How can I put a test in my macro to check to see if an error will be
produced when the line is run?

I tried (amongst others):

If IsError(windows(sheetname).activate) then etc.


Any help would be greatly appretiated.

Tom
 
Hi,

first loop throug all your windows with something like
Sub test()
For Each myWindow In Application.Windows
If myWindow.Caption = "test.xls" Then
found = True
End If
Next

If found = True Then
'...do something
Else
'... show an error message
End If
End Sub

regards

arno
 

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

Back
Top