![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 13
|
How would I write code that would not open the workbook if it is already open?
if Workbooks.Open Filename:="P:trial5.xls" already open then exit sub else Workbooks.Open Filename:="P:trial5.xls" end sub Thanks Wrecker |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
The following should work for you: -
Dim wb As Workbook Dim WorkbookOpen As Boolean For Each wb In Workbooks If wb.Name = "Trial5" Then WorkbookOpen = True Next wb |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Posts: 13
|
Is this what I need if the "trial5" workbook is already open? If it is already open, I need to ignore the open command.
Cant seem to make it work Thanks Wrecker |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
This will work for you Wrecker:
Dim wb As Workbook Dim WorkbookOpen As Boolean For Each wb In Workbooks If wb.Name = "Trial5" Then WorkbookOpen = True Next wb If WorkbookOpen = False Then Workbooks.Open Filename:="P:trial5.xls" Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|