[英]Launch a macro when Excel is off
Tl:dr Looking to see if there is any way to launch an Excel VBA macro when Excel is not open. Tl:dr寻找未打开Excel时是否有任何方法可以启动Excel VBA宏。
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).
唯一的问题是数据会在不方便的时间进行更新,即星期一早上05:00(GMT)和星期四早上01.15(GMT)。
What I need is a way of Excel self launching, collecting the data, update the spreadsheet, and then shutting down. 我需要的是一种Excel自我启动,收集数据,更新电子表格然后关闭的方法。 It's this possible?
这可能吗?
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. 首先,我需要安装第三方程序,并在需要时打开XLSM文件。
Once Excel has opened your spread-sheet you can create a Sub Workbook_Open()
routine to automatically run your macro. Excel打开电子表格后,您可以创建
Sub Workbook_Open()
例程以自动运行宏。 Your macro can close the spread-sheet once it has completed, and exit Excel. 宏完成后可以关闭电子表格,然后退出Excel。
Easier still - no need for VB scripting. 仍然更容易-不需要VB脚本。
Run WINDOWS TASK SCHEDULER, set up a job using Excel as the application. 运行WINDOWS TASK SCHEDULER,使用Excel作为应用程序设置作业。
You'll have to search for Excel.exe - because of my version, I found it here: 您必须搜索Excel.exe-因为我的版本,我在这里找到它:
"C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
Next supply the Argument as the FULL PATH to the macro-embedded Excel file. 接下来,将参数作为完整路径提供给嵌入宏的Excel文件。 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: 然后只需确保您的工作
Workbook_Open
在ThisWorkbook
模块中具有Workbook_Open
过程即可触发您的代码:
The best way is to write a VB.net script to do that. 最好的方法是编写一个VB.net脚本来做到这一点。
The easiest way is to left the PC turned on during the night and follow this simple tutorial: 最简单的方法是在夜间打开PC并遵循以下简单教程:
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 . 另一种方法是使用Windows Scheduler,如本答案所述 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.