Stupidità

Stupido è ciò che è nettamente peggiore del caso.
La stupidità consiste nel seguire regole che richiedono più tempo del caso o che non condurranno mai alla soluzione.

Intelligenza è quel che facciamo per arrivare a risolvere un problema in modo efficiente e senza sforzo.

(David Krakauer)

Scegliere l’account di outlook per inviare mail con vba excel

.SendUsingAccount = OutApp.Session.Accounts.Item(1)

Funziona!


Fonte:

https://www.rondebruin.nl/win/s1/outlook/account.htm

Use the mail account you want in your mail macro

Important read this :

The code on this page is only working when you use Outlook as your mail program.
Copy the code in a Standard module of your workbook, if you just started with VBA see this page.
Where do I paste the code that I find on the internet

 

Change Sender name and Reply address

The easiest way is to add this code line that change the sender name and reply address in the Outlook macro examples on my site.

‘The receiver can see the original mail address in the properties if he want
 .SentOnBehalfOfName = “””SenderName”” <Reply@Address.com>”

 

Use SendUsingAccount in Excel/Outlook 2007 or higher

If you want to mail from another account then your default mail account in Outlook 2007-2016 then you can use SendUsingAccount, this is added to the object model in Outlook 2007.

First add a reference to the Microsoft Outlook Library in your Excel workbook

1) Go to the VBA editor, Alt -F11
2) Tools>References in the Menu bar
3) Place a Checkmark before Microsoft Outlook ? Object Library
? is the Outlook version number

First we must know the account number that we want to use.
Run the macro below so you know the account number that you must use in the mail macro.

Sub Which_Account_Number()
'Don't forget to set a reference to Outlook in the VBA editor
    Dim OutApp As Outlook.Application
    Dim I As Long

    Set OutApp = CreateObject("Outlook.Application")

    For I = 1 To OutApp.Session.Accounts.Count
        MsgBox OutApp.Session.Accounts.Item(I) & " : This is account number " & I
    Next I
End Sub

Now you know the number of the account that you want to use in your mail macro you can use the following test subroutine that send a small text in an e-mail message. Change the mail address and the Item number “Item(1)” in the macro before you run it.

Sub Mail_small_Text_Change_Account()
'Only working in Office 2007-2016
'Don't forget to set a reference to Outlook in the VBA editor
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)

    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    On Error Resume Next
    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = strbody

        'SendUsingAccount is new in Office 2007
        'Change Item(1)to the account number that you want to use
        .SendUsingAccount = OutApp.Session.Accounts.Item(1)

        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Note : Got mails from 2016 users that that Set is needed before .SendUsingAccount

Abitudini

Ma l’astuzia dei tiranni nell’abbruttire i propri sudditi si dà a vedere nel modo più chiaro in quel che Ciro fece ai Lidi […] escogitò un grande espediente per assicurarsela: fece aprire bordelli, taverne e sale da gioco, emanando un’ordinanza che obbligava gli abitanti a frequentarli.

Discorso della servitù volontaria, Étienne de La Boétie (1548 a.c.)

las vegas.jpg

USA. Nevada. Las Vegas. 1967.                                                          Henri Cartier-Bresson
View profile

L’essere umano

“La quarta rivoluzione industriale è già presente e ha già cambiato il modo di fare impresa. Il mutamento è fuori e dentro le aziende ma necessita di essere governato. Non basta installare due sensori, aggiornare le infrastrutture e creare workflow digitali per dirsi pienamente all’interno della Industry 4.0. Spesso ci si dimentica che il lavoro, ancora per i prossimi anni, ruota attorno al perno dell’essere umano. Formare ed educare le persone alla trasformazione digitale è dunque il primo passo verso la normalizzazione della società su processi e metodi produttivi più intelligenti, sicuramente liquidi e, con molta probabilità, ottimizzati e convenienti.” 

 

We Change IT Forum: sfide e opportunità della rivoluzione 4.0