Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Waiting for OK (VB/VBA)

    I am trying to write a macro that needs to wait for an OK dialog box to open. I can do this with a Do loop, but I am not sure how to check to see if the Window/OK box is present.

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Waiting for OK (VB/VBA)

    Is this dialog box a userform created by you, or a standard MsgBox? If the latter, I don't think what you want is possible - msgbox dialogs are modal, i.e. all code stops execution when such a dialog is opened, so you can't react. Your code would resume execution when the dialog is closed by the user.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Waiting for OK (VB/VBA)

    How are you starting up the process your code needs to wait for? Shell?

  4. #4
    Lounger
    Join Date
    May 2003
    Location
    San Diego, California, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Waiting for OK (VB/VBA)

    Thanks for the replies!

    The process is actually started by another program. Figured out a way to check for the Window Title and then use a Do Loop is See if it is Open


    Declare Function GetForegroundWindow& Lib "user32" ()
    Declare Function GetWindowTextLengthA& Lib "user32" _
    (ByVal hwnd&)
    Declare Sub GetWindowTextA Lib "user32" _
    (ByVal hwnd&, ByVal lpsz$, ByVal cbMax&)


    Function ActiveWindowTitle$()
    ActiveWindow = GetForegroundWindow()
    TitleLen = GetWindowTextLengthA(ActiveWindow)
    Title$ = Space$(TitleLen )
    GetWindowTextA ActiveWindow,Title$,TitleLen+1
    ActiveWindowTitle$ = Title$
    End Function

    Sub Main

    Counter = 0

    Do
    Counter = Counter + 1
    If Counter > 30 Then Exit Do
    var$ = ActiveWindowTitle$()
    Wait 1
    Loop Until var$ = "MyCommands Editor"

    If var$ = "MyCommands Editor" Then
    MsgBox "Success"
    Else
    MsgBox "Time Out - Sorry"
    End If

    End Sub

Posting Permissions

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