In my outlook (this is for work) I have the ability to change the FROM so it comes from another email address than mine.
Can I have my VBA code select that FROM automatically? Right now I have to display the email, change it manually, then hit send...
Here's my code:
Code: Select all
Sub SendMail()
Debug.Print Now
'Create a new Microsoft Outlook session
Set appOutlook = CreateObject("outlook.application")
'Open the list to send to
Dim db As dao.Database
Set db = CurrentDb
Dim rst As dao.Recordset
Set rst = db.OpenRecordset("SELECT * FROM tblAddresses WHERE Sent = FALSE", dbOpenDynaset)
While Not rst.EOF
Debug.Print rst!Address
'create a new message
Set Message = appOutlook.CreateItem(olMailItem)
With Message
.Subject = "This is the subject"
Dim strBody As String
strBody = "This is the body<br><br><br>"
strBody = strBody & "And More body<br><br>"
.HTMLBody = strBody
.to = rst!Address
'.Cc = strCC
'.Attachments.Add ("C:\Temp\ShippingReport - " & strCostCenter & ".xls")
.Display
.Send
End With
'Update as sent
rst.Edit
rst!Sent = True
rst.Update
rst.MoveNext
Wend
'appOutlook = Nothing
Debug.Print Now
MsgBox "Done!"
End Sub
Code: Select all
.From = "otheraddress@test.com"
Any hep is appreciated