Application.OnTime Specifying both workbook and arguments

m1chael

New Member
Joined
Nov 12, 2013
Messages
16
Hi,

I'm looking to run Application.OnTime and specify both the workbook and some arguments. I can get them to work on their own, but not together.

For example, the following code works if "MacroToBeCalled" subroutine is in the same workbook where I set Application.OnTime.
Code:
  Application.OnTime Now(), "'MacroToBeCalled ""String To Send""'"

Also, the following code works if "MacroToBeCalled" subroutine is in the workbook called "Test File.xlsm", which is different to where I'm running this line of code.
Code:
  Application.OnTime Now(), "'Test File.xlsm'!MacroToBeCalled"

However, I can't find a way of sending parameters. I'm looking for something like the following, although this does not work.
Code:
  Application.OnTime Now(), "''Test File.xlsm'!MacroToBeCalled ""String To Send""'"

What is the format of the string I need to provide for this to work, if it is possible at all?

If you need more detail, I have two workbooks, say one is called A and one is called B. Both A and B contain a subroutine called MacroToBeCalled. I am using a button in workbook A, which uses Application.Run to run a macro in workbook B called SetOnTimeToRunMacro. What I want is for SetOnTimeToRunMacro subroutine in workbook B to call Application.OnTime to run the MacroToBeCalled in workbook B. However, when the Ontime is actually trigged, it's running MacroToBeCalled in workbook A instead of B, even though the Ontime is set in workbook B. If I remove the parameter and specify the workbook, then it works in workbook B.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I've discovered the answer to my own question. Will post here in case anyone else has the same issue:

The correct format to use is:

<code>Application.OnTime Now(), "'Test File.xlsm'!'MacroToBeCalled ""String To Send""'"

</code>The part before the ! mark, and the part after, should have single quotes.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,307
Members
449,218
Latest member
Excel Master

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