Americas

  • United States

Making Outlook work for us, Part III

Opinion
Apr 26, 20044 mins
Enterprise Applications

Instead of requiring appointments that are to run applications to be categorized, we could have the script check the subject of the appointment. If it started with, for example, “[Run]” we could have extracted the text that follows and hand that to the WSH shell.

Here in the world of Gearhead over the last two weeks we’ve looked at bending Outlook to our will so we could launch external applications when Outlook reminder events were triggered from calendar appointment items.

So, by golly, last week we did it! In just a few lines of code we added the facility we were after by capturing the reminder event in a Visual Basic for Applications script that checked to see if the appointment was categorized as “RunApp.” If it was, the script extracted the command to execute from the appointment body and handed it to a Windows Script Host (WSH) shell. Voilà! But how could we improve on this?

Well, instead of requiring appointments that are to run applications to be categorized, we could have the script check the subject of the appointment. If it started with, for example, “[Run]” we could have extracted the text that follows and hand that to the WSH shell.

Here’s last week’s code transmogrified into one subroutine and modified to do the above. So, if you tried last week’s code, delete the function RunApp and replace the Application_Reminder code with the following:

Private Sub Application_Reminder(ByVal Item As Object)

Dim Runstr As String

Dim WSHShell

If (TypeOf Item Is AppointmentItem) And _

(Left(Item.Subject, 5)=”[Run]”) _

Then

Item.ReminderSet=False

Item.Close(False)

Runstr=Trim(Right(Item.Subject,Len(Item.Subject)-4))

Set WSHShell=CreateObject(“wscript.Shell”)

WSHShell.Run Runstr, 1, False

Set WSHShell=Nothing

End If

End Sub

Note the underscores at the end of some of the lines; these let a statement span multiple lines. Also there is no underscore after “Then” – this defines the lines down to the “End if” as an “if block.” Without that the first line after “Then” would be assumed to be the end of the “If . . . then . . . ” code.

An alternative would be to run the external scheduled applications from task list items rather than from calendar items. The only real difference would be to use the following test for TaskItem in place of the AppointmentItem test:

If (TypeOf Item Is TaskItem) And _

And of course you could allow scheduled programs to be defined by either type of item:

If ((TypeOf Item Is AppointmentItem) Or _

(TypeOf Item Is TaskItem)) And _

That’s not too bad, but now that we’ve used this for a while we keep forgetting to set the reminder flag when we define an appointment or task item. Worse still, even when we do and we use appointments, we often forget to set the “remind beforehand” value to “0,” which makes the reminder happen before the event’s target time! Ugly.

The answer, our friend, is blowin’ in a form: Yep, you can create a custom form that fills in just the specific values for a task or appointment item. You could even create a drop-down list of predefined applications as a separate control and then, using VBScript in the form, set the subject value of the item. We will leave that as an exercise for the reader.

Another thing: If you want the external application to be launched silently you’ll have to set the third parameter of the call to WSHShell.Run to 7, thus:

WSHShell.Run Runstr, 7, False

See the Microsoft Developer’s Network Library for the ghastly details.

There are, however, some ugly bits to this. First, there is the issue we discussed last week of reminders not calling the reminder event handler until about 40 seconds after the scheduled event. Ugh.

Then there is a really ugly problem when a reminder event happens. Even though you theoretically have grabbed it in the code above and cleared the reminder flag, if you have enabled reminder popups the popup window will appear. It won’t have anything new in it, mind you, as you did clear the reminder from the item! Yuck.

So, there’s lots of room for improvement and polishing. If you have any code you’d like to share, let us know.

Reminders to gearhead@gibbs.com.

mark_gibbs

Mark Gibbs is an author, journalist, and man of mystery. His writing for Network World is widely considered to be vastly underpaid. For more than 30 years, Gibbs has consulted, lectured, and authored numerous articles and books about networking, information technology, and the social and political issues surrounding them. His complete bio can be found at http://gibbs.com/mgbio

More from this author