Premetto che sono nuovo del mondo di VBA e sto utilizzando una macro in Word per invio massivo di mail con allegato.
Utilizzo un file word con el corpo della mail, un file excel con le informazioni che devono cambiare e un altro file word con gli indirizzi mail e la posizione dei file allegati.
Il codice che utilizzo è questo:
- Codice: Seleziona tutto
Sub emailmergewithattachments()
Dim Source As Document, Maillist As Document, TempDoc As Document
Dim Datarange As Range
Dim i As Long, j As Long
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim mysubject As String, message As String, title As String
Set Source = ActiveDocument
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
With Dialogs(wdDialogFileOpen)
.Show
End With
Set Maillist = ActiveDocument
message = "Enter the subject to be used for each email message."
title = " Email Subject Input"
mysubject = InputBox(message, title)
For j = 1 To Source.Sections.Count - 1
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.Subject = mysubject
.Body = Source.Sections(j).Range.Text
Set Datarange = Maillist.Tables(1).Cell(j, 1).Range
Datarange.End = Datarange.End - 1
.To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(j, i).Range
Datarange.End = Datarange.End - 1
.Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
.Send
End With
Set oItem = Nothing
Next j
Maillist.Close wdDoNotSaveChanges
If bStarted Then
oOutlookApp.Quit
End If
MsgBox Source.Sections.Count - 1 & " messages have been sent."
Set oOutlookApp = Nothing
End Sub
Ho due problemi:
1) che la mail viene inviata solo in formato testo, senza immagini e senza firma
2) Vorrei inviare la mail da un altro indirizzo di posta elettronica e non da quello di default di Outlook.
Qualcuno potrebbe, per favore, aiutarmi?
Grazie mille