How do I make an open workbook the active workbook

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I have a workbook that is open, and would like to make it the active
workbook. I tried this code, but it does not work. Can anyone tell
me how to do this?

If (Not UtilitiesWorkbookIsOpen("myWorkbook.xls")) Then
MsgBox "Please open myWorkbook.xls"
Exit Sub
Else
ThisWorkbook.Activate
End If
 
Looking at the code provided it appears that you want to open if closed or
activate if not the active workbook.

Sub ActivateMyWorkbook() 'from MS
On Error GoTo ErrorHandler
Workbooks("Book2.xls").Activate
'The following line will halt the macro before the error handler
'is reached.
Exit Sub
ErrorHandler:
Workbooks.Open FileName:="Book2.xls"
End Sub
 

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