Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: Testing if workbook is open

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Yes.
    A userform is usually modal, always in 97.
    Modal means aint nothin happening until you close the userform.
    Tom

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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?

  6. #6
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •