Code:
Public Sub MakeAppointment(usingApplication As Object, aStart As Date, aEnd As Date, aAllDay As Boolean, aBody As String, aSubject As String, aLocation As String, aBusy As Integer, aRemind As Boolean)
Dim olApp As Object
Dim olApt As Object
Set olApp = usingApplication
Set olApt = olApp.createitem(1)
With olApt
.Start = aStart
.End = aEnd
.alldayevent = aAllDay
.body = aBody
.subject = aSubject
.Location = aLocation
.busystatus = aBusy
.reminderset = aRemind
.Save
End With
End Sub
Public Function ReadyOutlook() As Object
Dim olApp As Object
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application") 'If Outlook is already running set existing instance as olApp
'if Outlook is not running then creat an instance
If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set olNs = olApp.GetNamespace("MAPI")
'Se a aplicação não retornar nada, esta rotina criará uma e, neste caso, indica o caminho para acessar a pasta default
'Se retornar, apenas indicará o que acessar, neste caso, a pasta default
If olApp.ActiveExplorer Is Nothing Then
'Por default, a pasta de acesso à aplicação é a pasta onde encontra-se MAPI
olApp.Explorers.Add(olNs.GetDefaultFolder(9), 0).Activate
Else
Set olApp.ActiveExplorer.CurrentFolder = olNs.GetDefaultFolder(9)
'9 é o número que define o default
olApp.ActiveExplorer.Display
End If
Set ReadyOutlook = olApp
End Function
The Sub MakeAppointment simply makes an Outlook Appointment Item. Pretty straight forward. Its first argument is an Object that needs to be an Outlook Application.
The Function ReadyOutlook checks for the existence of an Outlook instance, and creates one if there isn't. Then it does some stuff to get to and show the calender. ReadyOutlook also returns an Outlook Application object.
So in use:
Code:
MakeAppointment(ReadyOutlook, arg2, arg3, arg4,....,arg8)
Seems to work just fine.
So, was I clever when I dreamed this up, or am I asking for trouble, not following good practices, angering Bill Gates.....?