using .SendUsingAccount and using an array to attach multiple documents

Oberon70

Board Regular
Joined
Jan 21, 2022
Messages
160
Office Version
  1. 365
Platform
  1. 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:

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.

1648552077254.png


Above is a shortened version

The invoices that meet the conditions are listed in a temporary table on another sheet.

1648552178246.png


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,
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
First you'll need to assign your account to olAccount . . .

VBA Code:
Set olAccount = OutlookApp .Session.Accounts.Item("domenic@something.com") 'change the name of the account accordingly

And then you can assign it to .SendUsingAccount . . .

VBA Code:
.SendUsingAccount = olAccount

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top