Using Excel vba Macro to be run through Windows Schedule Task

后端 未结 2 2001
生来不讨喜
生来不讨喜 2021-01-01 00:56

I have a Excel spreadsheet which I\'ve set up a timer to run code into a database. If the spreadsheet is open and the time now is the time set within the timeslot then it ex

相关标签:
2条回答
  • 2021-01-01 01:19

    In Windows Task Scheduler set: Action: Start a Program Program Script: The Excel.exe with path in full quotes. Add Arguments: The workbook you want to open with full path in quotes

    Check out this link: https://answers.microsoft.com/en-us/windows/forum/windows_8-performance/excel-files-can-not-be-opened-in-task-scheduler-in/aa6cf065-09ac-44d8-b6fb-a2f2ecd9b8cc

    Worked for me after banging my head for a couple hours.

    0 讨论(0)
  • 2021-01-01 01:22

    Hello what I would do is create this .VBS file and then use Windows Task Scheduler to execute this vbs file at the desired interval.

    Set fso = CreateObject("Scripting.FileSystemObject")
    curDir = fso.GetAbsolutePathName(".")
    
    Set myxlApplication = CreateObject("Excel.Application")
    myxlApplication.Visible = False
    Set myWorkBook = myxlApplication.Workbooks.Open( curDir & "\myTest.xlsm" ) 'Change to the actual workbook that has the Macro
    myWorkBook.Application.Run "Module1.HelloWorld" 'Change to the Module and Macro that contains your macro
    myxlApplication.Quit
    

    Application.Run Method (Excel)

    This example does require Excel to be installed on to the host running the scheduled task. If that host is a Server or a Desktop computer is your choice.

    The Windows Task Scheduler should be done as such for the Action portion of the task:

    Action: Start a program

    Program/script: C:\Windows\SysWOW64\cscript.exe

    Add arguments (optional): C:\Path_to_your_vbs\Your.vbs

    Start in (optional): C:\Path_to_your_vbs\

    0 讨论(0)
提交回复
热议问题