Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
I was wondering how I would have a macro detect whether or not a workbook is
open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
How about something like this
Sub Test() Dim myWB As Workbook Dim myString As String myString = "Book2" Set myWB = Nothing On Error Resume Next Set myWB = Workbooks(myString) On Error GoTo 0 If Not myWB Is Nothing Then Debug.Print myString & " is open" Else Debug.Print myString & " is not open" End If End Sub HTH, Barb Reinhardt "Rob" wrote: I was wondering how I would have a macro detect whether or not a workbook is open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
I like to use a function
Function bIsBookOpen(ByRef szBookName As String) As Boolean ' Rob Bovey On Error Resume Next bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing) End Function You can use this in your macro then If bIsBookOpen("Book1.xls") Then -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Rob" wrote in message ... I was wondering how I would have a macro detect whether or not a workbook is open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
Try:-
Sub marine() For Each wb In Workbooks If wb.Name = ("mybook.xls") Then MsgBox (wb.Name & " is open") End If Next wb End Sub Mike "Rob" wrote: I was wondering how I would have a macro detect whether or not a workbook is open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
They All Work for what I want to do... Now I just have to figure out which
one to use. THANK YOU ALL!!! R "Rob" wrote: I was wondering how I would have a macro detect whether or not a workbook is open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
#6
Posted to microsoft.public.excel.misc
|
|||
|
|||
Detecting if a Window/Workbook is Open
Hi Rob,
Good Point! Sometimes people like you have more luck than others ! regards, driller -- ***** birds of the same feather flock together.. "Rob" wrote: They All Work for what I want to do... Now I just have to figure out which one to use. THANK YOU ALL!!! R "Rob" wrote: I was wondering how I would have a macro detect whether or not a workbook is open. This is what I tried....... If Application.Windows("Book1.xls") = True Then Obviously it doesn't work but does someone know what would? Thanks Much. R |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to open Excel workbook in full size window | Excel Discussion (Misc queries) | |||
Macro to open print window and set to print entire workbook | Excel Discussion (Misc queries) | |||
Excel workbook does not open in open window on desktop | Excel Discussion (Misc queries) | |||
Can Excel open each workbook in a seperate window | Setting up and Configuration of Excel | |||
deleting second open window in a workbook | Excel Worksheet Functions |