Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Running Macro in another app

  1. #1
    New Member
    Join Date
    Apr 2002
    Location
    The LBC - Long Beach, CA
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a macro that runs a required macro in Word and then continues processing in Excel. The problem is that the Word macro takes about 30 minutes to run and I keep getting a message box that pops up in Excel saying that it's "waiting for another application to complete an OLE action."

    I know about the WAIT function but it seems to only allow specification of a time or delta-time. What I'm looking for is some way to tell the Excel macro to wait until the Word macro is done.

    Thanks

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The following uses an ontime method to test your PC every 3 seconds whether Word is open or closed. You can isolate your 'Post-Word' procedure and call the procedure in the instance Word has closed (in the event that your Word macro closes Word).

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public RunWhen As Date
    
    Sub test()
    Call StrtTimer
    h = FindWindow("OpusApp", vbNullString) 'Word's Class Name
    If h = 0 Then
    Call StpTimer
    MsgBox "Closed" 'Change this line to initiate your "Post-Word" procedure
    Else:
    End If
    End Sub
     
    Private Sub StrtTimer()
    RunWhen = Now + TimeSerial(0, 0, 3)
    Application.OnTime earliesttime:=RunWhen, procedure:="test", _
    schedule:=True
    End Sub
     
    Private Sub StpTimer()
    On Error Resume Next
    Application.OnTime earliesttime:=RunWhen, procedure:="test", _
    schedule:=False
    End Sub
    Hope this helps.

    _________________
    Cheers, NateO

    [ This Message was edited by: NateO on 2002-04-29 13:43 ]

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
  •