Windows Activate

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hi All

I've got this code in VB: Windows("ABC.xls").Activate. How can I ge
VB to check wether ABC.xls is open or not? Should ABC.xls not be ope
it needs to stop the process.

Please help:)

Stephe
 
Hi Stephen
try the following
Sub foo()
Dim wbk as workbook
On Error Resume Next
Set wbk = Workbooks("ABC.xls")
On Error GoTo 0
If wbk Is Nothing Then
msgbox "Workbook is not open"
exit sub
end if
msgbox "now activating workbook"
wbk.activate
end sub
 
Here is one that will activate if open or open if not. Works from a typed
name in a cell. I actually have it assigned to a double click event on a
menu workbook that first checks for a worksheet and then the workbook.

Sub GetWorkbook()
If ActiveCell.Value = "" Then Exit Sub
workbookname = ActiveCell.Value
On Error GoTo OpenWorkbook
Windows(workbookname & ".xls").Activate
Exit Sub
OpenWorkbook:
Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
End Sub
 
Hi Don.

Thanks for the code:) Very nice option you've put in there.


Stephen
 

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