Running Concurrent Macros

IREALLYambatman

Board Regular
Joined
Aug 31, 2016
Messages
63
Hey guys.. So I have a macro that is protected and that I don't have source code access to but that I can run and just want to automate (for work). It pops up a window with a list in it and I just want to select the third item in the list and hit tab and enter. I have worked out everything I need.. the only problem is that my macro just doesn't send the keystrokes after it runs his macro. I was under the impression that using Application.OnTime would be capable of allowing for a second macro to run in the background. But for some reason.. my macro finished first.. seconding those keystrokes nowhere instead of into the macro that I don't have access to.


Code:
Sub QForME(WorkBookName)'Path to File Containing Macro we want to run is C:\x\x.xls
'Name Of Macro we want to run is - QuantMain
    
    Dim wbb As Workbook
    On Error Resume Next
    
    Set wbb = Workbooks("x.xls")
    
    On Error GoTo 0
    If wbb Is Nothing Then Set wbb = Workbooks.Open("C:\x\x.xls")
    Workbooks(WorkBookName).Activate 'We active the file with our original macro as the macro we're about to run will need to work on that file.
    Application.OnTime Now + TimeValue("00:00:01"), "x.xls!MAIN"
    'Run "Macros.xls!MAIN"
    Sleep (1000)
    Application.SendKeys ("{Down}{Down}{Down}{Tab}{Enter}")
    
    wbb.Close False
    Set wbb = Nothing
        
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi there. Ive not used sendkeys much at all, but I found this reference in a microsoft help page which may be worth a try:
This method places keystrokes in a key buffer. In some cases, you must call this method before you call the method that will use the keystrokes. For example, to send a password to a dialog box, you must call the SendKeys method before you display the dialog box
The page was:https://docs.microsoft.com/en-us/office/vba/api/excel.application.sendkeys
So if I understand this correctly, putting the sendkeys line before the run MAY do it for you (but I doubt it).

John
 
Upvote 0
.
What does "His macro" do ? If there is always an anticipated change in your workbook from "His macro", create additional code at the beginning of your macro to check for that change.

If the change exists ... run your macro. If the change does not exist ... do nothing / exit your macro.
 
Upvote 0
Hi there. Ive not used sendkeys much at all, but I found this reference in a microsoft help page which may be worth a try:
The page was:https://docs.microsoft.com/en-us/office/vba/api/excel.application.sendkeys
So if I understand this correctly, putting the sendkeys line before the run MAY do it for you (but I doubt it).

John
Actually that was most of the problem solved! Now it actually does the down arrows/tab button.. Just seems to ignore hitting enter (I'm guessing it moves too fast?). I'll keep trying a work-around for it.
 
Upvote 0
.
What does "His macro" do ? If there is always an anticipated change in your workbook from "His macro", create additional code at the beginning of your macro to check for that change.

If the change exists ... run your macro. If the change does not exist ... do nothing / exit your macro.

His macro does a bunch of mathematical calculations then bring up a selection window, and waits for the user to select the right item from the item list box and continue. I just need to automate that part.. Seems like I'm most of the way there.. I just need to hit enter now.
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,245
Members
453,026
Latest member
cknader

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