+ Reply to Thread
Results 1 to 4 of 4

Help with Task scheduler to run a Macro

  1. #1
    Registered User
    Join Date
    07-03-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    7

    Help with Task scheduler to run a Macro

    Hi! I need help filling out the form for task scheduler.

    Goal: have a macro run everyday at the same time - file name c:\Script.xlsm
    My macro runs perfectly.

    I have a run.bat file
    and a Script.vbs file.

    It runs the macro if I click on the run.bat file.

    run.bat code: cscript script.vbs "C:\script.xlsm"

    Script.vbs code:
    Dim args, objExcel

    Set args = WScript.Arguments
    Set objExcel = CreateObject("Excel.Application")

    objExcel.Workbooks.Open args(0)
    objExcel.Visible = True

    objExcel.Run "test"

    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close(0)
    objExcel.Quit

    So all the parts seem to be working, but I can't get the task scheduler to work. It opens the excel file but doesn't run the macro.

    could someone please tell me how to fill out this form?
    picture attached. taskscheduler.jpg

    Thanks!

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Help with Task scheduler to run a Macro

    In your workflow it should be just the bat file.
    However, going up one leve you can also just start cscript with 2 optional arguments - script name and the excel file
    Now, actually the simplest solution would be to use Workbook_Open event to start your macro. In this case you will need just to start (i.e. open) the excel file with the macro. no need to use the vbs script or bat file. Note that you may need to change your macro a bit as I see that vbs scropt saves and close the xlsm file. You will need to add this to your macro
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Help with Task scheduler to run a Macro

    OK, I test it and it actually fails to run macro if you run the bat file.
    So I tried to run the vbs file with path to the excel file as optional argument and it works fine. see attached image

    Screenshot 2015-08-07 09.21.40.png

    Anyway I think best solution is to skip also the vbs file.

  4. #4
    Registered User
    Join Date
    07-03-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help with Task scheduler to run a Macro

    THANK YOU!!! works perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run Macro with Windows Task scheduler
    By scottatbuckman in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-29-2014, 12:05 PM
  2. Running Excel from task scheduler. Scheduler doesn't end
    By tony h in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-31-2013, 09:49 PM
  3. Windows Task Scheduler, Run Macro.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-03-2013, 03:02 PM
  4. Task Scheduler to Run Macro While Computer is Locked
    By w.m.christensen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2013, 12:44 PM
  5. Run Excel and macro using Windows Task Scheduler
    By MilroyD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2013, 11:24 PM
  6. windows task scheduler VBS script to run macro
    By els050676 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-16-2013, 09:13 AM
  7. Connecting VBA macro to OS Task Scheduler
    By vierx2007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2010, 02:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1