Oberon70
Board Regular
- Joined
- Jan 21, 2022
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
Hi,
My Outlook 365 has 3 email accounts that I can select in From:
However, I can't seem to get the code to change from the default mailbox and I am due to security I am not able to use send on behalf on. I am hoping it is a simple error in the code below:
My objective is to send from another mailbox I work out of and to have this email attached the documents that are determined by conditions I have set. My database table keeps track of different flags that is picking the correct invoices that I want to send.
Above is a shortened version
The invoices that meet the conditions are listed in a temporary table on another sheet.
I was thinking using the dictionary function would be the best way to match (exist) when I run a loop through the above table? and then when it is found to exist I store the path into an array? and then use a loop when the email code to add the attachments to the email.
The other thing I will try after getting the above working is to create insert a temporary table I have created with my code into the middle of the body of my email.
Anyway, 1st is to see what is wrong with SendUsing and the best way to attached the documents to the email.
thanks,
My Outlook 365 has 3 email accounts that I can select in From:
However, I can't seem to get the code to change from the default mailbox and I am due to security I am not able to use send on behalf on. I am hoping it is a simple error in the code below:
VBA Code:
Public Sub EmailTest()
Dim OutlookApp As Outlook.Application
Dim objEmail As Object
Dim StrBody As String
Set OutlookApp = New Outlook.Application
Set objEmail = OutlookApp.CreateItem(0)
StrBody = "Hi," & vbNewLine & vbNewLine & "This is my first email from Excel" & _
vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"VBA Coder" 'VbNewLine is the VBA Constant to insert a new line
On Error Resume Next
With objEmail
.SendUsingAccount = olAccount
.To = "Supes@waynetech.com"
.CC = ""
.BCC = ""
.Subject = "Testing - It is a go!!!!"
.HTMLBody = StrBody
.Display
End With
On Error GoTo 0
Set OutlookApp = Nothing
Set objEmail = Nothing
End Sub
My objective is to send from another mailbox I work out of and to have this email attached the documents that are determined by conditions I have set. My database table keeps track of different flags that is picking the correct invoices that I want to send.
Above is a shortened version
The invoices that meet the conditions are listed in a temporary table on another sheet.
I was thinking using the dictionary function would be the best way to match (exist) when I run a loop through the above table? and then when it is found to exist I store the path into an array? and then use a loop when the email code to add the attachments to the email.
The other thing I will try after getting the above working is to create insert a temporary table I have created with my code into the middle of the body of my email.
Anyway, 1st is to see what is wrong with SendUsing and the best way to attached the documents to the email.
thanks,