Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 740
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open Excel workbook in full size window Eunice Anderson Excel Discussion (Misc queries) 8 February 24th 07 12:46 AM
Macro to open print window and set to print entire workbook retseort Excel Discussion (Misc queries) 1 October 27th 05 11:00 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM
Can Excel open each workbook in a seperate window JVC Dude Setting up and Configuration of Excel 2 January 15th 05 01:01 AM
deleting second open window in a workbook mark in leisure Excel Worksheet Functions 2 November 8th 04 02:09 PM


All times are GMT +1. The time now is 07:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"