![]() |
|
#1
|
|||
|
|||
|
With the macro below I can very nicely send my present Word document (2016) using Outlook (2016) as e-mail application.
Sub From_WORD__Outlook() ActiveWindow.EnvelopeVisible = Not ActiveWindow.EnvelopeVisible ActiveDocument.MailEnvelope.Introduction = "This is a WORD document" With ActiveDocument.MailEnvelope.Item .Recipients.Add "MyAddress@MyMail.com" .Subject = "Experiment" End With End Sub However, I want to send the e-mail using a specific account. I tried to use the macro below, but that doesnot changes the default Account as presented in the active Word document. (It does change however the present account in Outlook, but apparently that is not the same as the one presently valid in WORD) Set objOL = CreateObject("Outlook.Application") For Each oAccount In objOL.Session.Accounts If oAccount.DisplayName = "reguired@emailad" Then Set oMail = objOL.CreateItem(olMailItem) oMail.SendUsingAccount = oAccount End If Next A second problem is that in Recipients.Add I cannot select a group of preselected accounts from the active addressbook Can anyone help me solve these problems? Thank you Regards, WivanS |
|
#2
|
||||
|
||||
|
Instead of mailenvelope, try the following
Code:
Sub Send_As_HTML_EMail()
'Graham Mayor - http://www.gmayor.com - Last updated - 14 Jul 2017
'Requires the code from http://www.rondebruin.nl/win/s1/outlook/openclose.htm
'to either retrieve an open instance of Outlook or open Outlook if it is closed.
Dim bStarted As Boolean
Dim olApp As Object
Dim oItem As Object
Dim oAccount As Object
Dim objDoc As Object
Dim objSel As Selection
Dim strRecipient As String
Dim strSubject As String
Dim strAccount As String
strRecipient = "someone@somewhere.com"
strSubject = "This is the message subject"
strAccount = "account display name"
ActiveDocument.Range.Copy
Set olApp = OutlookApp()
For Each oAccount In olApp.Session.Accounts
If oAccount.DisplayName = strAccount Then
Set oItem = olApp.CreateItem(0)
With oItem
Set .SendUsingAccount = oAccount
.BodyFormat = 2
.Display
Set objDoc = .GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.PasteAndFormat Type:=wdFormatOriginalFormatting
.To = strRecipient
.Subject = strSubject
'.Send
End With
Exit For
End If
Next oAccount
lbl_Exit:
Set oItem = Nothing
Set oAccount = Nothing
Set olApp = Nothing
Set objDoc = Nothing
Set objSel = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thank you, Graham, for the quick response.
When I try the code I get an errorcode on the line: Set olApp = OutlookApp () with the statement: "Sub or Function not defined" I tried with Set olApp = Outlook.Application () But I get the same result. Regards, WivanS |
|
#4
|
||||
|
||||
|
Did you pay attention to the instructions in at the top of the macro?
Quote:
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#5
|
|||
|
|||
|
Thank you, Guessed.
You put me on the right track: I changed Set olApp = OutlookApp () into Set olApp = GetObject(, "Outlook.Application") as in the macro of Ron de Bruin. So now in principle it works fine. I have one question though. Perhaps someone could solve that as well: In my Outlook AddressbookI have a number of recipients gathered in GROUP. I would like to have as recipient this GROUP (several addresses, but in the To: field only visible as "+ GROUP"). Could you please help me with this also? Many thanks! Regards, WivanS |
|
#6
|
||||
|
||||
|
I'm not sure you can do that. AFAIK, the group name has to resolve to its members in order to send.
Normally when you want to hide the names of other people the email went to, you put all the names in the BCC field instead of the To field.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#7
|
|||
|
|||
|
Thank you, Guessed.
Not having GROUP as my group recipients is the least of my worries. With all the assistance I've got I have a very solid macro now. Thank you very much. Regards, WivanS |
|
#8
|
||||
|
||||
|
Quote:
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#9
|
|||
|
|||
|
Hi Graham,
You're right. I did copy the macro from Ron de Bruin, but didn't mention it explicitly. Thanks for your assistant and remarks. Regards, WivanS |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cannot change/select/Add older .PST file from Account Settings n O2016 | Hixpix | Outlook | 0 | 09-26-2017 03:51 AM |
How do I select all text highlighted in a specific colour?
|
bertietheblue | Word | 2 | 04-15-2016 12:30 PM |
signature for specific account
|
Mr.T | Outlook | 1 | 02-17-2015 03:10 PM |
| Mark BCC when emails is sent from specific account | vijanand1279 | Outlook | 0 | 05-27-2014 09:59 PM |
Using ActiveWorkbook.EnvelopeVisible = True to send part of a sheet as an email.
|
bshawnr | Excel Programming | 1 | 04-12-2014 05:02 AM |