0

Tl:dr Looking to see if there is any way to launch an Excel VBA macro when Excel is not open.

Long version: I have a macro that fetches data from a specific set of websites, and updates the spreadsheets accordingly. The only problem with this is that the data updates at inconvenient times, namely Monday mornings at 05.00 (GMT), and Thursday mornings at 01.15 (GMT).

What I need is a way of Excel self launching, collecting the data, update the spreadsheet, and then shutting down. It's this possible?

Community
  • 1
  • 1
Clauric
  • 1,826
  • 8
  • 29
  • 48
  • 1
    Create a VbScript file and write code to run your excel macro and schedule it to run at desired time. – ManishChristian Apr 03 '17 at 13:52
  • This [question and its answers](http://stackoverflow.com/q/10232150/7648526) should help. – SteveES Apr 03 '17 at 14:16
  • Yes use Windows TASK SCHEDULER to invoke the process. Should be a fairly easy process to simply include for START A PROGRAM, the app name, EXCEL, and the file name (including the path). Be sure the XLS has a WORKBOOK_OPEN subroutine within THISWORKBOOK. If you'd like I can spell this out in a formal Answer. Please let me know. – Bill Roberts Apr 03 '17 at 15:17

3 Answers3

2

If I were you, I would it this way:

At First I install a third-party program, with I open the XLSM file, when it is needed.

Once Excel has opened your spread-sheet you can create a Sub Workbook_Open() routine to automatically run your macro. Your macro can close the spread-sheet once it has completed, and exit Excel.

Oliver
  • 37
  • 6
2

Easier still - no need for VB scripting.

Run WINDOWS TASK SCHEDULER, set up a job using Excel as the application.

enter image description here

You'll have to search for Excel.exe - because of my version, I found it here:

"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE"

Next supply the Argument as the FULL PATH to the macro-embedded Excel file. For my testing, I invoked a file on my desktop:

C:\Users\br12260\Desktop\TimeSeries.xls

Then just be sure that your workbook has an Workbook_Open procedure in ThisWorkbook module to trigger your code:

enter image description here

Bill Roberts
  • 1,127
  • 18
  • 30
1

The best way is to write a VB.net script to do that.

The easiest way is to left the PC turned on during the night and follow this simple tutorial:

Public dTime As Date
Dim lNum As Long

Sub RunOnTime()
    dTime = Now + TimeSerial(0, 0, 10)
    Application.OnTime dTime, "RunOnTime"

    lNum = lNum + 1
    If lNum = 3 Then
        Run "CancelOnTime"
    Else
        MsgBox lNum
    End If

End Sub

Sub CancelOnTime()
    Application.OnTime dTime, "RunOnTime", , False
End Sub

Another way is use the Windows Scheduler, as written in this answer.

Nicolaesse
  • 2,554
  • 12
  • 46
  • 71