Looking to see if Workbook is open
I am trying to write VBA code that will look first to see if another workbook
is open, if open then go to sheet 1, if not open, then open it and go to sheet 1. You see I might need to go to this sheet several different times during the day and I don't want to keep opening and closing the sheet. Steve |
Looking to see if Workbook is open
Dim oWB As Workbook
On Error Resume Next Set oWB = Workbooks("myBook") On Error GoTo 0 If oWB Is Nothing Then Set oWB = Workbooks.Open("C:\myDir\myBook.xls") End If oWB.Worksheets("Sheet1").Activate -- HTH RP (remove nothere from the email address if mailing direct) "caldog" wrote in message ... I am trying to write VBA code that will look first to see if another workbook is open, if open then go to sheet 1, if not open, then open it and go to sheet 1. You see I might need to go to this sheet several different times during the day and I don't want to keep opening and closing the sheet. Steve |
Looking to see if Workbook is open
Thanks Bob, the code worked just the way I want.
Steve "Bob Phillips" wrote: Dim oWB As Workbook On Error Resume Next Set oWB = Workbooks("myBook") On Error GoTo 0 If oWB Is Nothing Then Set oWB = Workbooks.Open("C:\myDir\myBook.xls") End If oWB.Worksheets("Sheet1").Activate -- HTH RP (remove nothere from the email address if mailing direct) "caldog" wrote in message ... I am trying to write VBA code that will look first to see if another workbook is open, if open then go to sheet 1, if not open, then open it and go to sheet 1. You see I might need to go to this sheet several different times during the day and I don't want to keep opening and closing the sheet. Steve |
All times are GMT +1. The time now is 11:40 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com