1
I am trying to access a shared mailbox however keep getting an error when rebooting outlook.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim myRecipient As Outlook.Recipient
Dim myNamespace As Outlook.NameSpace
Set olApp = Outlook.Application
Set myRecipient = myNamespace.CreateRecipient("accounts payable")
Set Items = GetNS(olApp).GetSharedDefaultFolder(myRecipient, olFolderInbox).Folders("printed invoices")
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
MsgBox "You moved an item into the 'Stuff' folder."
Dim MsgReply As Outlook.MailItem
Set MsgReply = item.Reply
With MsgReply
.Subject = "Re " & item.Subject
.HTMLBody = "Hello" & MsgReply.HTMLBody
.Send
End With
Set MsgReply = Nothing
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
2"keep getting an error" - what error? We are not mind readers. – DavidPostill – 2016-03-26T21:43:09.327
Sorry, the error is "Run-time error '91': Object variable or With block variable not set" And it highlights the "Set GetNS = app.GetNamespace("MAPI") line when debugging – J Froese – 2016-03-26T22:03:23.673
I don't speak VBA but you seem to be trying to set a Function
GetNS
to some other value. Are you allowed to do do such things in VBA? – DavidPostill – 2016-03-27T07:24:19.427So I have resolved that issue but get the same run-time error 91 with the following code: – J Froese – 2016-03-28T03:40:03.267