My code works when Outlook is open, but when closed it only sends from my primary address. Anyone have any ideas?
Code:
Dim olApp As Outlook.Application, olAppt As Outlook.AppointmentItem, myRecipient As Outlook.Recipient, olNS As Outlook.NameSpace
Dim i As Long, blnOLOpen As Boolean, strBody As String, olAttach As Outlook.Attachments
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
blnOLOpen = True
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set olNS = olApp.GetNamespace("MAPI")
Set olFromBox = olNS.CreateRecipient("TheSharedBox")
olFromBox.Resolve
If (olFromBox.Resolved) Then
Set oCalendar = olNS.GetSharedDefaultFolder(olFromBox, olFolderCalendar)
On Error Resume Next
Set olAppt = oCalendar.Items.Add("IPM.Appointment")
If (Err.Number) Then
MsgBox "You do not have access to create a meeting from the '" & SEND_FROM_MAILBOX & "' mailbox!", vbExclamation
GoTo CleanUp
End If
Else
MsgBox "Unable to locate the '" & SEND_FROM_MAILBOX & "' mailbox!", vbExclamation
GoTo CleanUp
End If