1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Sub Mail_Every_Worksheet_With_Address_In_A1_PDF()
'Working only in 2007 and up
Dim sh As Worksheet
Dim TempFilePath As String
Dim TempFileName As String
Dim FileName As String
'Temporary path to save the PDF files
'You can also use another folder like
'TempFilePath = "C:\Users\Ron\MyFolder\"
TempFilePath = "C:\Users\Ludivine\Documents\XXDivers\info cuisine\Frédéric Blanc"
'Loop through every worksheet
For Each sh In ThisWorkbook.Worksheets
FileName = "test11"
'Test A1 for a mail address
If sh.Range("A7").Value Like "?*@?*.?*" Then
'If there is a mail address in A1 create the file name and the PDF
TempFileName = TempFilePath & "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss") & ".pdf"
FileName = RDB_Create_PDF(Source:=sh, _
FixedFilePathName:=TempFileName, _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'If publishing is OK create the mail
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:=sh.Range("A7").Value, _
StrCC:="", _
StrBCC:="", _
StrSubject:="This is the subject", _
Signature:=True, _
Send:=False, _
strbody:="Bonjour, <BR><BR>Voici la commande pour le restaurant Georges Blanc<BR><BR>Merci d'avance<BR><BR>Frédéric"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
Next sh
End Sub |
Partager