'VBA code in excel to copy a field and paste into a new outlook email [closed]
I currently have a vba code that is activated by a button in excel that copies certain information from the sheet into an outlook email. Having updated to win64 and updating the declare statements etc. I can not get it to open an outlook email window. What is the new code to open the outlook application window from within excel via win64
Solution 1:[1]
The following code works like a charm on my machine with Office x64 installed:
Dim applOL As Outlook.Application
Dim miOL As Outlook.MailItem
'Create a new instance of the Outlook application. Set the Application object as follows:
Set applOL = New Outlook.Application
'create mail item:
Set miOL = applOL.CreateItem(olMailItem)
With miOL
.To = "[email protected]"
.Subject = "Mail Automation"
.Body = "Sending the Active Excel Workbook as attachment!"
'add host workbook as an attachment to the mail:
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
'clear the object variables:
Set applOL = Nothing
Set miOL = Nothing
Don't forget to add an Outlook COM reference in your VBA environment.
Also you may find the following articles helpful:
- How To: Create and send an Outlook message programmatically
- How To: Fill TO,CC and BCC fields in Outlook programmatically
Also take a look at the Automating Outlook from Other Office Applications article.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eugene Astafiev |