mohammedus
New Member
- Joined
- Sep 9, 2011
- Messages
- 1
I have a Macro in Excel which creates and send's an email using a group mailbox as the sent from email.
For emails sent using this macro I would like to save the sent items in the group mailbox rather than my default one. I have created the following line but cannot get it to work:
Set Item.SaveSentMessageFolder = OutApp.Session.Folders("Mailbox - Group Mailbox").Folders("Sent Items")
Complete Macro:
Sub run()
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("sheet1")
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "Group Mailbox"
.to = "test@email.com"
.ReplyRecipients.Add "Group Mailbox"
.Subject = " Invoice IN00000XXXX"
Set Item.SaveSentMessageFolder = OutApp.Session.Folders("Mailbox - Group Mailbox").Folders("Sent Items")
MyDate = WorksheetFunction.Text(Now, "hh:mm:ss")
If MyDate >= "12:00:00" Then
Greeting = "Good Afternoon"
Else
Greeting = "Good Morning"
End If
.body = Greeting
.body = .body & "<BR><BR>"
.body = .body & "Please find attached Invoice IN00000XXXX. " & "If you have any queries, please do not hesitate to contact us by replying to this email."
.body = .body & "<BR><BR>" & "To access the attached document you will require Adobe® Acrobat® reader, which is free to download from www.adobe.co.uk/reader/"
.body = .body & "<BR><BR><BR>" & "Kind Regards" & "<BR><BR><BR>"
.body = .body & "<i>The Finance Team</i>"
.htmlbody = .body
If Worksheets("Sheet1").Range("A1") = "" Then
Else
.Attachments.Add Range("A1").Value
End If
If Worksheets("Sheet1").Range("A2") = "" Then
Else
.Attachments.Add Range("A2").Value
End If
If Worksheets("Sheet1").Range("A3") = "" Then
Else
.Attachments.Add Range("A3").Value
End If
.display
End With
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
For emails sent using this macro I would like to save the sent items in the group mailbox rather than my default one. I have created the following line but cannot get it to work:
Set Item.SaveSentMessageFolder = OutApp.Session.Folders("Mailbox - Group Mailbox").Folders("Sent Items")
Complete Macro:
Sub run()
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("sheet1")
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
.SentOnBehalfOfName = "Group Mailbox"
.to = "test@email.com"
.ReplyRecipients.Add "Group Mailbox"
.Subject = " Invoice IN00000XXXX"
Set Item.SaveSentMessageFolder = OutApp.Session.Folders("Mailbox - Group Mailbox").Folders("Sent Items")
MyDate = WorksheetFunction.Text(Now, "hh:mm:ss")
If MyDate >= "12:00:00" Then
Greeting = "Good Afternoon"
Else
Greeting = "Good Morning"
End If
.body = Greeting
.body = .body & "<BR><BR>"
.body = .body & "Please find attached Invoice IN00000XXXX. " & "If you have any queries, please do not hesitate to contact us by replying to this email."
.body = .body & "<BR><BR>" & "To access the attached document you will require Adobe® Acrobat® reader, which is free to download from www.adobe.co.uk/reader/"
.body = .body & "<BR><BR><BR>" & "Kind Regards" & "<BR><BR><BR>"
.body = .body & "<i>The Finance Team</i>"
.htmlbody = .body
If Worksheets("Sheet1").Range("A1") = "" Then
Else
.Attachments.Add Range("A1").Value
End If
If Worksheets("Sheet1").Range("A2") = "" Then
Else
.Attachments.Add Range("A2").Value
End If
If Worksheets("Sheet1").Range("A3") = "" Then
Else
.Attachments.Add Range("A3").Value
End If
.display
End With
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub