Consulting

Results 1 to 3 of 3

Thread: Export to PDF (specific sheets) if cells in Input sheet are >0, if condition is met

  1. #1
    VBAX Newbie
    Joined
    Aug 2020
    Posts
    2
    Location

    Export to PDF (specific sheets) if cells in Input sheet are >0, if condition is met

    Dear, if anyone knows please help me to solve this problem, didn't find anywhere anything similar, and with VBA well im not quite good.

    Here is description of problem:
    Sheets (Report 1, 2, 3, and or 4) needs to be exported as one PDF if example condition on Input Sheet is >0
    PDF document need to export on desktop
    Document name needs to be as C18
    By this example reports would be exported Report1, Report 3, Report 4.
    Example condidtion is changing, so sometimes there will be exported just one report, sometimes all four of them
    *If possible, to open email outlook, with saved PDF, with adress in sheet Input on cell C19, ready to be sent

    Attachment excel is below.

    Many thanks if anyone helps!
    Screenshot_1.jpg
    Attached Files Attached Files

  2. #2
    VBAX Newbie
    Joined
    Aug 2020
    Posts
    2
    Location
    Guys people in mrexcel.com already posted solution, i paste it here for purpose of education and solve problem for others, just move table on B9, and code work.

    Public Sub Save_Sheets_As_PDF()

    Dim DesktopFolder As String
    Dim PDFfile As String
    Dim cell As Range
    Dim replaceSelected As Boolean
    Dim currentSheet As Worksheet

    DesktopFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & ""

    Set currentSheet = ActiveSheet
    replaceSelected = True
    With ThisWorkbook
    PDFfile = DesktopFolder & .Worksheets("Input").Range("C17").Value
    For Each cell In .Worksheets("Input").Range("B10:B13")
    If cell.Offset(, 1).Value > 0 Then
    .Worksheets(cell.Value).Select Replace:=replaceSelected
    replaceSelected = False
    End If
    Next
    End With

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, OpenAfterPublish:=False, IgnorePrintAreas:=False

    currentSheet.Select

    End Sub


    II Second solution:


    Sub ExportPdf()
    Dim hojas() As String, dFolder As String
    Dim i As Long, n As Long

    dFolder = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator

    With Sheets("Input")
    For i = 10 To 13
    If .Range("C" & i) > 0 Then
    ReDim Preserve hojas(n)
    hojas(n) = Sheets(.Range("B" & i).Value).Name
    n = n + 1
    End If
    Next

    If n > 0 Then
    Sheets(hojas).Select
    ActiveSheet.ExportAsFixedFormat xlTypePDF, dFolder & .[C17] & ".pdf", 0, True, False, , , False
    .Select
    End If
    End With
    End Sub

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,645
    welcome to the forum.

    http://www.vbaexpress.com/forum/faq...._new_faq_item3
    when you post your question to multiple forums pleas add a link to your thread in other forums. and pls do this in all your threads in all forums.

    btw, thanks for the info on mrexcel
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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