http://www.networkworld.com/columnists/2004/0412gearhead.html NOTE: The SelfCert.exe program is not part of the standard installation of Microsoft Office. If you need to install the SelfCert.exe program, rerun Setup for Office CD1 and click Add or Remove Features. Click the plus sign (+) next to Office Tools; click Digital Signature for VBA Projects and then click Run from My Computer. Click Update Now. (it worked, don't worry about installing too many features). ________________ create certificate To get Outlook to trust your macros and only complain when it finds a macro from an unrecognized source, we are going to "sign" our macros. Start by navigating to the Office directory (usually "C:\Program Files\Microsoft Office\OFFICEnn,": C:\Program Files\Microsoft Office\Office In this subdirectory you will find selfcert.exe - go on, run it! Selfcert.exe generates a self-signed digital certificate. All you need to do is enter a name for the certificate and click "OK," and you should get a message indicating that a certificate was created (read more). ________________ install your new certificate in the Trusted Root Certification Authorities Run on the Start menu and launch mmc.exe, the Microsoft Management Console utility. From the File menu click "Add/Remove Snap-In" and then click "Add." In the resulting list, select "Certificates" and click "Add" at the bottom of the dialog, and then click on "My User Account," "Finish," "Close" and finally "OK." You are now back in the main window of MMC, so expand the branch: Console Root\Certificates - Current User\Personal\Certificates Under the leaf of the branch above, you should find the certificate you just created. > Now you have to right click and then drag and drop this certificate to the branch: Console Root\Certificates - Current User\Trusted Root Certification Authorities\Certificates . . . and when you release the mouse you must select "Copy here" rather than "Move here" - the certificate needs to be in both locations. (Stick with us here, we're almost done.) (quit and 'save settings to Console1, but don't know if it's necessary) ________________ > Next close Outlook if it is open then restart it so Outlook recognizes the new configuration. > Run the Visual Basic Editor (alt-F11) > In the editor window select "Tools | Digital Signature" and click "Choose" and select the certificate you have just created. > Click "OK" and restart Outlook, which lets the new settings take effect. (Click save macro ThisOutLookSession) > When VB Editor starts this time you will see a new dialog that informs you that the macro has been signed with an untrusted certificate, so you should check "Always trust macros from this source" and then click on "Enable macros." ________________ First, start the Visual Basic Editor, by Alt + F11. In the left pane you will see a hierarchy starting with Project1 (VbaProject.OTM), under which you will see (when you expand the branches) Microsoft Office Outlook Objects and under that ThisOutlookSession. The right pane now will list the various subroutines and functions you have defined by loading macros and extensions under Outlook. If there is no right pane, double-click on ThisOutlook... Put the following code in that pane: ________________________________________ Private Sub Application_Reminder(ByVal Item As Object) If (TypeOf Item Is AppointmentItem) And _ (Item.Categories = "AppRun") Then _ Call RunApp(Item) End Sub Public Function RunApp(ByVal Item As AppointmentItem) Dim WSHShell Item.ReminderSet = False Item.Close (False) 'close reminder popup Set WSHShell = CreateObject("wscript.Shell") WSHShell.Run Trim(Item.Body), 1, False Set WSHShell = Nothing End Function ________________________________________ The first line sets up an event handler for Outlook reminders. When a task or an appointment triggers a reminder, the handler subroutine named Application_Reminder will be called. The calling routine - Outlook itself - will pass the handler an object so we first must test the object to see if it is an AppointmentItem. The alternatives are MailItem, MeetingItem or TaskItem, and we could choose to launch applications from any of these. TaskItems would be a sensible alternative as well as or instead of AppointmentItems. Once we know the object is an AppointmentItem we can test its Categories attribute value to see if that equals AppRun (you could look for any category or categories you like - nothing restricts you to just one). If the value is what we're looking for, we now call the function RunApp. RunApp first clears the ReminderSet property of the item and then executes the close method, which updates the object's properties. This should suppress the reminder alert dialog if you have enabled it, but the dialog seems to get called anyway (although the reminder we just cancelled does not appear). This is very annoying. If you know how to prevent this, please let us know. Next we call the Windows Script Host to access a native Windows shell. This shell lets us run a program locally, manipulate the contents of the registry, create a shortcut or access a system folder. We are going to run a program. Advertisement: The trim function strips leading and trailing spaces from the string that we extract from the object's "body" - that's the optional descriptive text, which is another property of the object. We then pass this string to the shell instructing the shell to execute it. The next argument, "1," specifies that the window should be activated and displayed (if the window is minimized or maximized, the system restores it to its original size and position). The final argument, "False," causes control to immediately return to our script ignoring any error code from the shell (in other words, if the program doesn't exist or something else goes wrong our script doesn't care). When the reminder actually occurs will depend on how far in advance of the event we set it. But don't assume that the application will be launched exactly on the minute that you specify - on our test system the reminder usually triggered about 40 seconds after the target time was reached - an odd behavior that is because of the internal architecture of Outlook. If you need accurate launching of an application you might want to ensure that the reminder occurs a few minutes before the desired start time and hand the details of the program to be executed to an external application along with the start date and time (which would be referenced in our example as Item.Start). _________________________________________ added new category AppRun put the address of the speed disk application in the body of the event (outlook calendar)
If this was useful, or you have a question, let me know. [ more ]