Outlook Task Scheduler to Run Access Subs

☆樱花仙子☆ 提交于 2019-12-11 09:35:21

问题


I have Access Macros that run a series of queries, form a tables, and send those tables to multiple recipients. This works fine, but I'm being increasingly asked to supply an increasing number of reports on a set day of the week.

Rather than use my calendar to remind me to open Access and run these Macros, can I run VBA in Outlook to run an Access macro on a certain day?


回答1:


Rather than use my calendar to remind me to open Access and run these Macros, can I run VBA in Outlook to run an Access macro on a certain day?

There are ways you can do this with .BAT files and windows task scheduler, but you can also do it with Outlook VBA. I have a few calendar events which have this exact purpose, to execute code and clear the reminder.

First you need to add an event handler to fire when your reminders get set.

Private WithEvents olRemind As Outlook.Reminders

You then need to initialize the WithEvents. I do this everytime a reminder happens because I sometimes break code or hard stop, which loses the event handler.

Private Sub Application_Reminder(ByVal Item As Object)
    Set olRemind = Outlook.Reminders
End Sub

Then, you want to process the event on your calendar. The way I have mine setup is I add a specific category for the event I want to fire. This helps make my calendar clearer. You can do this in a variety of ways.

I also then dismiss the reminder so it doesn't show up.

'fire off automatic macros based on recurring reminders
Private Sub olRemind_BeforeReminderShow(Cancel As Boolean)
    Dim objRem As Reminder

    For Each objRem In olRemind
        'get categories
        Dim rmdrCategories As String

        rmdrCategories = objRem.Item.categories

        'call the macro based on category
        If InStr(rmdrCategories, "whateverYouWantTheReminder") > 0 Then

            'only run if this reminder is visible
            If objRem.IsVisible Then

                'This code is specific to whatever macro you want to run
                Dim mydb As Object                
                Set mydb = GetObject("...pathToDatabase.mdb")
                mydb.Application.Run "YourMacroName"
                mydb.Application.Quit
                Set mydb = Nothing


                 objRem.Dismiss
                Cancel = True
            End If

        End If

    Next objRem

End Sub


来源:https://stackoverflow.com/questions/26514690/outlook-task-scheduler-to-run-access-subs

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