How to schedule a call to an MS Access macro?

孤街浪徒 提交于 2019-12-23 12:49:23

问题


I'm looking to schedule a call to an MS Access macro. This macro uses a .csv file (that I get daily) to update a SharePoint calendar. Could someone please explain how to schedule a daily call to run this macro (I'm using Access 2003, say EventsCalendar.accdb and macro called Run1) on my Windows 7 machine? I need to automate it to run every morning.

Thanks!


回答1:


Write a VBScript script that can run the macro straight from Windows. You can do this by first creating an Access application object in your script and then placing this Access object before all calls in the script which need it. For example,

' RunMyMacro.vbs

set accessApp = CreateObject("Access.Application")

accessApp.OpenCurrentDatabase "C:\db\mydb.accdb"
accessApp.DoCmd.RunMacro "MyMacroName"
accessApp.CloseCurrentDatabase
accessApp.Quit

set accessApp = nothing

This script is now runnable from the Windows shell or from the command line:

C:\db>cscript //B //Nologo  RunMyMacro.vbs

And so you can schedule it as a Windows scheduled task.



来源:https://stackoverflow.com/questions/14821405/how-to-schedule-a-call-to-an-ms-access-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!