+ Reply to Thread
Results 1 to 10 of 10

Run Macro with Windows Task scheduler

Hybrid View

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Run Macro with Windows Task scheduler

    Ive been looking at a bunch of examples, but everything that I have tried just gives me errors. Can someone help me with what code to use to make a vbs script to run in windows task scheduler that will...

    Open "J:\Groups\BSHEETS\SDA\New EOD.xlsm"
    Run the macro named "EODPrint"
    Save the workbook
    and close the workbook
    Leaving excel open if other instances exist.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Run Macro with Windows Task scheduler

    Hi,

    You need to get the scheduler to open the workbook, and then ensure that the following is in the Workbook Open event

    Call "EODPrint"
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: Run Macro with Windows Task scheduler

    The issue there, is that other people put information into this spreadsheet daily, and I don't want it to print every time that its opened. Only at my scheduled time.

  4. #4
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Run Macro with Windows Task scheduler

    Quote Originally Posted by scottatbuckman View Post
    The issue there, is that other people put information into this spreadsheet daily, and I don't want it to print every time that its opened. Only at my scheduled time.

    You can add If statements to check the user/computer/time and decide if you want it to run a macro or not.

    http://office.microsoft.com/en-us/ex...080557165.aspx

    I would recommend you consider building a workbook template for multiple data submissions and have the macro workbook do reconciliation.

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Run Macro with Windows Task scheduler

    I have used two methods.

    1. Make your own workbook and put in Windows Schedule and make it do what is needed in its Open event. In this method, I added a MsgBox so it will wait for a time so that I can cancel it should I want to edit it first.

    2. Add a BAT file to Windows Schedule and pass parameters that your file would act on. For this method, see: http://www.vbforums.com/showthread.php?t=366559

  6. #6
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: Run Macro with Windows Task scheduler

    So if I go the route of using another workbook, how would I go about running the macro in the workbook im needing to? I tried this, but it don't work.

    Private Sub Workbook_Open()
    
    Workbooks.Open "J:\Groups\BSHEETS\SDA\New EOD.xlsm"
    Run "EODPrint"
    
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    End Sub

  7. #7
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: Run Macro with Windows Task scheduler

    Quote Originally Posted by scottatbuckman View Post
    So if I go the route of using another workbook, how would I go about running the macro in the workbook im needing to? I tried this, but it don't work.

    Private Sub Workbook_Open()
    
    Workbooks.Open "J:\Groups\BSHEETS\SDA\New EOD.xlsm"
    Run "EODPrint"
    
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    End Sub
    'Application.Run ("'Workbookname'!macroname")
    Application.Run ("'New EOD.xlsm'!EODPrint")

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Run Macro with Windows Task scheduler

    Check out the help for Application.Run.

    e.g.
    Application.Run "'" & ThisWorkbook.Path & "\RunExample.xlsm'!Module2.Button807_Click", 3
    Last edited by Kenneth Hobson; 04-29-2014 at 12:00 PM.

  9. #9
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: Run Macro with Windows Task scheduler

    I looked at it quite a bit, and tryed all kinds of things, the workbook opens, but i get an error saying the macro might not be available.

    I also tried

    Application.Run "New EOD.xlsm!EODPrint"

  10. #10
    Registered User
    Join Date
    01-22-2014
    Location
    Potosi, MO
    MS-Off Ver
    Excel 2013
    Posts
    64

    Re: Run Macro with Windows Task scheduler

    that worked, thanks slx

+ 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. Open Excel workbook and run macro using Windows task scheduler
    By MilroyD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 01:17 PM
  2. Windows Task Scheduler, Run Macro.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-03-2013, 03:02 PM
  3. 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
  4. 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
  5. Windows Task Scheduler Question
    By tekman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2008, 05:00 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