run macros in sequence

smithrd6

Board Regular
Joined
Dec 13, 2005
Messages
150
How to run macros in sequence, meaning, when macro 1 is finished, macro 2 fires.

thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Derivative question (apologies if this should be a new thread):

If I run say, a Java program, that's initiated through a command prompt call from VBA, is there a way to have the macro pause until the console window closes (i.e. the Java program is complete).

I currently just have a message box pop up which I manually close at the appropriate time (thus acting as a pause in VBA). I suppose I could have the Java program create a file at its completion and have the VBA loop until that file has been created.

This isn't a major problem, just wondering if there's something that's less of a work-around...
 
Upvote 0
Sure. here is an routine that shells the Windows Calc.exe and waits until the user is done with the calculator - ( see if you can adapt it to your Java Program )

Code:
Option Explicit

Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Const SYNCHRONIZE As Long = &H100000
Private Const INFINITE As Long = &HFFFFFFFF

Private Sub Test()
 
    Dim lPid As Long, lPhndl As Long
    
    lPid = Shell("Calc.exe")
    lPhndl = OpenProcess(SYNCHRONIZE, 0, lPid)
    If lPhndl Then
        Do
            WaitForSingleObject lPhndl, INFINITE
            CloseHandle lPhndl
            Exit Do
            DoEvents
        Loop
    End If
    MsgBox "code is now resuming"

End Sub
 
Upvote 0
Thanks Jaafar. Works like a charm.

Changed...

Code:
    lPid = Shell("Calc.exe")

to...

Code:
    dim strCommands as String
    strCommands = "cd c:\pathname\ & java filename"
    lPid = Shell("cmd.exe /c" & strCommands)


Also discovered that if the Excel help window is open, you have to click and refocus on Excel in order for the code to resume.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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