Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2019, 09:06 AM
WivanS WivanS is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Novice
Select specific Account after using EnvelopeVisible
 
Join Date: Aug 2019
Posts: 5
WivanS is on a distinguished road
Question Select specific Account after using EnvelopeVisible

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
Reply With Quote
  #2  
Old 08-12-2019, 08:51 PM
gmayor's Avatar
gmayor gmayor is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 08-13-2019, 12:13 AM
WivanS WivanS is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Novice
Select specific Account after using EnvelopeVisible
 
Join Date: Aug 2019
Posts: 5
WivanS is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 08-13-2019, 12:25 AM
Guessed's Avatar
Guessed Guessed is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Did you pay attention to the instructions in at the top of the macro?
Quote:
'Graham Mayor - Graham Mayor - Home Page - Last updated - 14 Jul 2017
'Requires the code from Test if Outlook is open and open Outlook with VBA
'to either retrieve an open instance of Outlook or open Outlook if it is closed.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 08-13-2019, 01:50 AM
WivanS WivanS is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Novice
Select specific Account after using EnvelopeVisible
 
Join Date: Aug 2019
Posts: 5
WivanS is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 08-13-2019, 04:17 AM
Guessed's Avatar
Guessed Guessed is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #7  
Old 08-13-2019, 05:43 AM
WivanS WivanS is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Novice
Select specific Account after using EnvelopeVisible
 
Join Date: Aug 2019
Posts: 5
WivanS is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 08-13-2019, 08:59 PM
gmayor's Avatar
gmayor gmayor is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Quote:
You put me on the right track: I changed
Set olApp = OutlookApp ()
into
Set olApp = GetObject(, "Outlook.Application")
Except that isn't the right track. You should have copied the complete function from the web site and called it from the macro as I indicated. This then ensures that Outlook is always opened or accessed correctly.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #9  
Old 08-13-2019, 11:54 PM
WivanS WivanS is offline Select specific Account after using EnvelopeVisible Windows 10 Select specific Account after using EnvelopeVisible Office 2016
Novice
Select specific Account after using EnvelopeVisible
 
Join Date: Aug 2019
Posts: 5
WivanS is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


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
Select specific Account after using EnvelopeVisible How do I select all text highlighted in a specific colour? bertietheblue Word 2 04-15-2016 12:30 PM
Select specific Account after using EnvelopeVisible 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
Select specific Account after using EnvelopeVisible Using ActiveWorkbook.EnvelopeVisible = True to send part of a sheet as an email. bshawnr Excel Programming 1 04-12-2014 05:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft