+ Reply to Thread
Results 1 to 10 of 10

Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi All
    I found 1 website with great code and guidance. Just that, it is too complicated and i do not know what i should i do 1st to my own workbook.
    After downloading the sample workbook, i found that, there is "functionsModule"'s Modules and the code that i wanted to use is "CreatePDFMail".

    I had attached my workbook name "Screening.xlsm" and Sample of workbook from MSDS name "PDF-Example".

    What should i do on my workbook "Screening.xlsm"? Do i need to write down things like the sample workbook on, "Microsoft Excel Objects"> Info(Info)? Before proceeding with VBA Code?
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi cychua

    Do you wish to email the entire workbook?
    Where will the Email address be stored?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    I wish to create pdf on selected sheet, example sheet name "hbl". Only.

    And attach it to outlook. User manually key in email address.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi cychua

    The attached code will do as you require. Place it in a General Module. You can call the Code either by Button (assign Create_PDF to the Button) or by assigning a Key Board short cut to the Procedure. Let me know of issues.
    Option Explicit
    Dim myPath As String
    
    Sub Create_PDF()
        Dim strSubject As String
        Dim strBody As String
        Dim strTo As String
        Dim strCC As String
        Dim Filename As String
    
        myPath = ThisWorkbook.Path & "\"
        strSubject = "Enter Your Subject Here"  '<----------------
        strBody = "Enter Your Body Message Here"  '<----------------
        strTo = ""
        strCC = ""
    
        Sheets("HBL").Select
        
        '*********************************
        ' This will be the Title of the PDF
        
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                myPath & "What Ever You Wish " & Format(Date, "dd_mm_yyyy") & ".pdf" _
                , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
        Filename = myPath & "What Ever You Wish " & Format(Date, "dd_mm_yyyy") & ".pdf"
       '*********************************
    
        If Filename <> "" Then
            RDB_Mail_PDF_Outlook Filename, strTo, strCC, strSubject, strBody, False
        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
        Kill Filename
    End Sub
    
    
    Function RDB_Mail_PDF_Outlook(FileNamePDF As String, strTo As String, strCC As String, _
            strSubject As String, strBody As String, Send As Boolean)
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = strTo
            .CC = strCC
            .BCC = ""
            .Subject = strSubject
            .Body = strBody
            .Attachments.Add FileNamePDF
            If Send = True Then
                .Send
            Else
                .Display
            End If
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Function

  5. #5
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi Jaslake
    It works nicely for me. But how to add on a little technical code, like
    On HBL sheet, i had made 2 printable pages. Possible to create PDF is filled range only? Example like page 2's cell A72 is filled then creating PDF on 2 pages of sheet(HBL)

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi cychua

    I don't understand the request...please try again.

  7. #7
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi Jaslake
    Sorry for my bad explaination.
    On my sheet "HBL" i made the form which printable in 2 pages.
    I wish to create pdf on page 2 where cell "A72" is filled only. Instead of entire sheet (5)/HBL.

    Is this possible?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi cychua

    Try this
    Option Explicit
    Dim myPath As String
    
    Sub Create_PDF()
        Dim strSubject As String
        Dim strBody As String
        Dim strTo As String
        Dim strCC As String
        Dim Filename As String
        Dim LR As Long
    
        myPath = ThisWorkbook.Path & "\"
        strSubject = "Enter Your Subject Here"  '<----------------
        strBody = "Enter Your Body Message Here"  '<----------------
        strTo = ""
        strCC = ""
    
        Sheets("HBL").Select
        
        LR = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious).Row
        If LR < 72 Then
            With ActiveSheet.PageSetup
                .PrintArea = "A1:J64"
            End With
        Else
            With ActiveSheet.PageSetup
                .PrintArea = "A1:J118"
            End With
        End If
    
        '*********************************
        ' This will be the Title of the PDF
        ' Change "What Ever You Wish" to your desired name"
    
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                myPath & "What Ever You Wish " & Format(Date, "dd_mm_yyyy") & ".pdf" _
                , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
        Filename = myPath & "What Ever You Wish " & Format(Date, "dd_mm_yyyy") & ".pdf"
        '*********************************
    
        If Filename <> "" Then
            RDB_Mail_PDF_Outlook Filename, strTo, strCC, strSubject, strBody, False
        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
        Kill Filename
    End Sub
    
    
    Function RDB_Mail_PDF_Outlook(FileNamePDF As String, strTo As String, strCC As String, _
            strSubject As String, strBody As String, Send As Boolean)
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = strTo
            .CC = strCC
            .BCC = ""
            .Subject = strSubject
            .Body = strBody
            .Attachments.Add FileNamePDF
            If Send = True Then
                .Send
            Else
                .Display
            End If
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Function

  9. #9
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: Need Guidance and Alteration on My Own Workbook - Creating PDF and Mail

    Hi Jaslake
    Wonderful! Just like what i want! Very appreciate for your quote and thank you so much.

    Regards
    Cychua

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1