Grazie Enrico.
Ho provato con il tuo codice e poi sono andato al link da te consigliato.
Ho smanettato un pò ed ho scelto e modificato leggermente per quanto mi serviva
i seguenti codici, il primo per inviare mail inserendo il corpo nel codice
ed il secondo per prelevare il corpo da un file txt oppure due (nel secondo file un eventuale firma)
la function del secondo codice va copiata nello stesso modulo del codice.
Esempio 1:
- Codice: Seleziona tutto
Sub Mail_small_Text_Outlook()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4" & Cells(1, 1).Value '<= Eventuale valore preso da cella folgio attivo
'strbody = "Dear " & Cells(1, 1).Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date"
On Error Resume Next
With OutMail
.To = "pinco@email.it;pallino@email.it"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line" & Cells(1, 1).Value
.Body = strbody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Display '.Send or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Esempio 2:
- Codice: Seleziona tutto
Sub Mail_Text_From_Txtfile_Outlook()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "pinco@email.it"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = GetBoiler("C:\test.txt") & _
GetBoiler("C:\test2.txt") '<= Inserire se si vuole utilizzare un eventuale secondo file (Firma)
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
Ho lasciato anche il riferimento al sito da dove ho copiato e adattato per le mie esigenze
perchè è una fonte attendibile e con molti esempi.
Se qualcuno mi sapesse dire se è possibile inserire in automatico la firma digitale presente e di default
outlook ve ne sarei grato oltremodo.
Grazie a tutti ed attendo eventuali commenti.