chrisasir2
New Member
- Outlook version
- Outlook 2016 32 bit
- Email Account
- Office 365 Exchange
Hi Diane,
I am reading emails from one subfolder called TEST and changing the subject text and then forwarding the emails to different recipient.
I wrote the VBA subroutine. Its not erroring out stating property is read only.
Kindly help me
---- Code
Sub Retrieve_subfolder_emails()
Dim olMail As MailItem
Dim ns As NameSpace
Dim olinboxfolder As MAPIFolder, olsubfolder As MAPIFolder
Dim msg As MailItem
Set ns = GetNamespace("MAPI")
Set olinboxfolder = ns.GetDefaultFolder(olFolderInbox)
Set olsubfolder = olinboxfolder.Folders("Test")
' Reading the mails from subfolder TEST
For Each msg In olsubfolder.Items
Set olMail = CreateItem(olMailItem)
With olMail
.To = "abcd@gmail.com"
.CC = ""
.Subject = "New subject Test1 :" & msg.Subject
.Body = msg.Body
.Attachments = msg.Attachments
.Send
End With
Set olMail = Nothing
Next msg
Set olsubfolder = Nothing
Set oinboxfolder = Nothing
Set ns = Nothing
End Sub
Regards,
Anand
I am reading emails from one subfolder called TEST and changing the subject text and then forwarding the emails to different recipient.
I wrote the VBA subroutine. Its not erroring out stating property is read only.
Kindly help me
---- Code
Sub Retrieve_subfolder_emails()
Dim olMail As MailItem
Dim ns As NameSpace
Dim olinboxfolder As MAPIFolder, olsubfolder As MAPIFolder
Dim msg As MailItem
Set ns = GetNamespace("MAPI")
Set olinboxfolder = ns.GetDefaultFolder(olFolderInbox)
Set olsubfolder = olinboxfolder.Folders("Test")
' Reading the mails from subfolder TEST
For Each msg In olsubfolder.Items
Set olMail = CreateItem(olMailItem)
With olMail
.To = "abcd@gmail.com"
.CC = ""
.Subject = "New subject Test1 :" & msg.Subject
.Body = msg.Body
.Attachments = msg.Attachments
.Send
End With
Set olMail = Nothing
Next msg
Set olsubfolder = Nothing
Set oinboxfolder = Nothing
Set ns = Nothing
End Sub
Regards,
Anand