Testing if workbook is open

robfo0

Active Member
Joined
Feb 19, 2002
Messages
281
Hi everyone, another question. I found this function posted by Juan, but Im having trouble using it. here is my macro:

sub test()
'other macro stuff here
'Open
Workbooks.Open Filename:= _
"S:FileServerShared FilesUnsecuredUnsecured Contract Selector.xls", ReadOnly:=True

wait5:
Application.Wait (Now + TimeValue("0:00:05"))
If WBisOpen("Unsecured Contract Selector") = True Then
GoTo wait5
Else
MsgBox ("pasting info")
End If



End Sub

Function WBisOpen(Bk As String) As Boolean
Dim T As Workbook
Err.Clear
On Error Resume Next
Set T = Workbooks(Bk)
WBisOpen = Not (Err.Number > 0)
Err.Clear
On Error GoTo 0
End Function


It seems like when the other workbook opens, it stops the macro which checks to see if its open? i never get the msgbox! help!

Thanks
This message was edited by robfo0 on 2002-04-15 15:35
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi
I could be wrong, but change this and re-try:

wait5:
Application.Wait (Now + TimeValue("0:00:05"))
WBisOpen "Unsecured Contract Selector"
If WBisOpen Then GoTo wait5
MsgBox ("pasting info")

Tom
 
Upvote 0
I tried your code, and added another message to see if the code was running.

when i execute the macro, the new workbook opens (the workbook being opened executes a userform upon opening), but neither of the message boxes come up. Does the code freeze when a userform opens?? Here is the code i tried:

wait5:
MsgBox ("waiting5")
Application.Wait (Now + TimeValue("0:00:05"))
WBisOpen "Unsecured Contract Selector"
If WBisOpen("Unsecured Contract Selector") Then GoTo wait5
MsgBox ("pasting info")


help! thanks :)
 
Upvote 0
Yes.
A userform is usually modal, always in 97.
Modal means aint nothin happening until you close the userform.
Tom
 
Upvote 0
well...even when im finished with the userform and it closes...the macro does NOT continue...with the code above, i should always get a message right? but when i run the macro, the sheet opens, i do the userform stuff, i get NO messages at all :( any ideas?
 
Upvote 0
wellp...i havnet done this up until now, but i'd really appreciate any ideas on this problem :( bump!

My code seems to stop when i open another file (which runs a user form on open)!! help!
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,938
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top