Sub INVIOMAIL()
Dim AppMail As Object 'Outlook.Application
Dim NewMail As Object 'Outlook.Application
Dim miaDir
Dim MioWBK As Workbook
Dim MioSheet As Worksheet
Dim Nome As String
Dim Cognome As String
Dim indirizziTO As String
Dim IndirizziCC As String
Dim NomeFile As String
Dim Oggetto As String
Dim Testo As String
Set MioWBK = ActiveWorkbook
Set MioSheet = ActiveWorkbook.Sheets("Certificato")
miaDir = Range("dati!j3")
Nome = MioSheet.Range("F12")
Cognome = MioSheet.Range("B12")
NomeFile = "Certificato di proroga di_" & Nome & "_" & Cognome & ".pdf"
ActiveWorkbook.Sheets("CERTIFICATO").ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
miaDir & "/" & NomeFile, Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
On Error Resume Next
Set AppMail = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
Set AppMail = CreateObject("Outlook.Application")
AppMail.Session.Logon
If Err <> 0 Then
MsgBox "Could not load Outlook", vbOKOnly + vbInformation, "Error report"
End
End If
End If
indirizziTO = MioSheet.Range("d8")
IndirizziCC = MioSheet.Range("F18")
Set NewMail = AppMail.CreateItem(0)
Oggetto = "Invio certificato di proroga" & vbCrLf & vbCrLf
Testo = "Invio quanto in allegato. Saluti. GV " & vbCrLf
With NewMail
.To = indirizziTO
.CC = IndirizziCC
.Subject = Oggetto
.body = Testo & .body
.Attachments.Add miaDir & "/" & NomeFile
.Display
End With
'NewMail.SEND
ActiveWorkbook.SaveAs FileName:=Range("Dati!f3") & Range("Dati!b1").Value & ".xlsm"
ActiveWorkbook.Close
Application.Quit
End Sub
|