Forum Discussion

Joe Gray's avatar
Joe Gray
Copper Contributor
May 30, 2017
Solved

Re: Macro to save as PDF with auto filename as cell value

Hi I recently used the following Macro, provided by Gary's Student, to create a PDF from an active sheet, generate a unique Filename based on a cell ref and save it to a specific location.   This m...
  • Andrew Jones's avatar
    Jun 02, 2017

    This is code I use.

    End Sub

    Private Sub Email()
    
        Dim objOutlook As Object
        Dim objMail As Object
        Dim signature As String
        Dim oWB As Workbook
        Set oWB = ActiveWorkbook
        
        Set objOutlook = CreateObject("Outlook.Application")
        Set objMail = objOutlook.CreateItem(0)
        
            
        With objMail
            .Display
        End With
            signature = objMail.HTMLbody
        With objMail
            .To = oWB.Sheets("Sheet1").Range("A1").Value
            ''.SentOnBehalfOfName = ""
            .Subject = strMySubject
            ''.body = "Dear Sir," & vbNewLine & vbNewLine & "Add stuff here" & vbNewLine & vbNewLine & signature
            .HTMLbody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & 4 & Chr(34) & ">" & "Dear Sir," & "<br> <br>" & "Add stuff here" & "<br> <br>" & signature & "</font>"
            .Attachments.Add (strSaveFileName + ".pdf")
            .Display
        End With
    
        Set objOutlook = Nothing
        Set objMail = Nothing
        
    End Sub

Resources