Sending as pdf instead of xlsm!

Abouya

Registered User.
Local time
Yesterday, 16:02
Joined
Oct 11, 2016
Messages
88
Good afternoon,

I'm trying to alter this below code to send the spreadsheet as pdf. Thanks for helping me out.

Code:
Sub Mail_Click()
 
 
 Dim Msg As String, Ans As Variant
 Dim wb1 As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileExtStr As String
    Dim OutApp As Object
    Dim OutMail As Object
    EmailTo = Cells(1, 10)
    ccto = Cells(1, 11)
    

Emailrecipients.Show
    
   Msg = "Clicking 'Yes' will Directly email Your PO Requisition to the recipients you have chosen!"
     
        Ans = MsgBox(Msg, vbYesNo)
    Select Case Ans
Case vbYes
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    
    
    Set wb1 = ActiveWorkbook

    'Make a copy of the file/Open it/Mail it/Delete it
    'If you want to change the file name then change only TempFileName
    TempFilePath = Environ$("temp") & "\"
    TempFileName = Replace(wb1.Name, ".pdf", "") & " #" & Range("H5") & " " & Format(Now, "dd-mmm-yy")
    FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))

    wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
     
     'Create the PDF
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="TempFilePath" & "TempFileName" & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=OpenPDFAfterCreating
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = EmailTo
        .CC = ccto
        .BCC = "amine.bouya@gmail.com"
        .Subject = "PO Requisition #" & " " & Range("H5")
        .Body = "PO Requisition #" & " " & Range("H5") & vbCrLf & "Vendor: " & Range("C5") & vbCrLf & "Total: " & Range("J43") & "$" & vbCrLf & vbCrLf & "Please Find the file attached for more details."
        .Attachments.Add TempFilePath & TempFileName & FileExtStr
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0
    
     

    
    'Delete the file
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

MsgBox "Your File was successfully sent to" & " " & Range("j1") & " " & "and" & " " & Range("k1")

 Case vbNo
GoTo Quit:
    End Select
Quit:



End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom