• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run specific macro at specific time

YasserKhalil

Well-Known Member
Hello everyone
I need to run a specific macro named "Test" at specific time .. exactly at 12 pm
and at all days except Friday and Monday

Thanks advanced for help
 
If Excel is open, you can use Application.OnTime. If it won't be open, you need to use Task Scheduler to open Excel and a Workbook_Open routine to run the code.
 
Thanks a lot for reply
I don't know but it seems there is a problem with the link
Can you provide us the best solution provided in this discuss please?
 
Strange. I can open the link without problem. Is it asking for you to register?

Here's initial code I had posted there. This you need to put in a vbscript file and edit to suit your situation.
Code:
'Write Sheet's full path here
strPath = "C:\MyPath\Book1.xlsm"
'Write the macro name including module
strMacro = "Sheet1.Macro2"
'Create an Excel instance and set visibility of the instance
Set objApp = CreateObject("Excel.Application")
objApp.Visible = False
'Open workbook; Run Macro; Save Workbook with changes; Close; Quit Excel
Set wbToRun = objApp.Workbooks.Open(strPath)
objApp.Run wbToRun.Name & "!" & strMacro
wbToRun.Save
wbToRun.Close
objApp.Quit
'Leaves an onscreen message!
MsgBox "Code Running Was Successful!", vbInformation
 
Thank you very much Mr. Shivallabha for reply
In fact I ma still a little confused .. the code in put in vbscript file .. Will the code add the task to Task Scheduler? or it will run the macro only
Mr. Debaser It is a way to remind me during work of specific tasks to do ..as I forget most of the times
 
What I mean is why don't you manually add the task to task scheduler? It's a one time operation.
 
You never answered my original question - will Excel already be open? If it will, you can just use Application.OnTime to schedule a macro.

Do you not have Outlook?
 
Sorry Mr. Debaser I didn't notice the question
As for the device will be open but excel may be or may be not open ..
If opened at the specific time I can manage a code using Application.OnTime as you mentioned ( I know that point) but what if the excel is not open ..that's my problem so I had to use task scheduler
 
Thank you very much Mr. Shivallabha for reply
In fact I ma still a little confused .. the code in put in vbscript file .. Will the code add the task to Task Scheduler? or it will run the macro only
Mr. Debaser It is a way to remind me during work of specific tasks to do ..as I forget most of the times
Above code is for running a specific macro.

1. Create VBScript which runs specific macro like one showed above and save it as *.vbs file. For this you can use Notepad.
2. Schedule the vbscript as per your requirements.
 
Back
Top