Buon pomeriggio a tutti,
spero che possiate aiutarmi con il mio incubo 🙄
in due fogli separati ho 2 tabelle (1 per ogni foglio).
Ho una macro che invia le email con allegato .pdf che sarebbe il foglio attivo da cui la invio (tipo fattura).
In questa macro ho inserito una MsgBox dove se clicco si, invia il pdf ad un'altra email, con allegato il pdf, se clicco no esce tranquillamente.
Il mio intento sarebbe quella di usare il MsgBox sempre con "si" e "no",
dove se clicco "si" invia l'email,con allegato e con la tabella del Foglio2; se clicco "no" invia l'email, con allegato e con la tabella del Foglio3.
Spero di aver spiegato bene, sotto troverete il codice che uso..
Vi ringrazio anticipatamente per l'aiuto e buon weekend 😎
SubmailFoglioAttivoPDF()
Sub MailFoglioAttivoInPDF1()
Dim OutApp As Object
Dim OutMail As Object
Dim u As Variant
Dim StrMsg As String
mioTesto = Cells(10, 8)
mioTesto2 = Cells(11, 10)
StrMsg = ""
StrMsg = StrMsg & "<html xmlns='http://www.w3.org/1999/xhtml'>"
StrMsg = StrMsg & "<body>"
StrMsg = StrMsg & _
"[Release of]" & mioTesto & "
" & _
"
Prego, i documenti "
" & _
"
Pinco Pallino
</body></html>"
MailDestinatario = Range("J25")
MailOggetto = Range("H10").Value & " " & Range("J10").Value
u = Application.GetSaveAsFilename(Range("H10").Value, "PDF Files (*.pdf), *.pdf")
If VarType(u) <> vbString Then Exit Sub
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=u, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, From:=3, To:=4, OpenAfterPublish:=False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = MailDestinatario
.Subject = MailOggetto
.HTMLBody = StrMsg
.Attachments.Add u
.Display
'.Send
End With
MailDestinatario2 = Range("J25")
If MsgBox("vuoi inviare l'email?", vbOKCancel, "Conferma invio") = vbOK Then
StrMsg = ""
StrMsg = StrMsg & "<html xmlns='http://www.w3.org/1999/xhtml'>"
StrMsg = StrMsg & "<body>"
StrMsg = StrMsg & _
"Buongiorno,"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = MailDestinatario2
.Subject = "Documenti"
.HTMLBody = StrMsg
.Display
'.Send
End With
End If
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub