Creating a macro to export PDFs in a dropdown list

overwatch

New Member
Joined
Jul 12, 2017
Messages
1
Hi all,

I have statements I need to generate PDFs for in excel. In my workbook there are 2 sheets, one for the calculation and one that is the statement itself.

The statement sheet needs to be generated into a PDF, it's full of vlookups that reference the calculation sheet and the lookup value is the dropdown cell in the statement sheet.

I need a macro that will export PDFs from the dropdown list, thank you.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
See if this works for you. I've made a few assumptions: the statement sheet is named "Statement"; the dropdown cell is E2 and is a data validation in-cell dropdown; the PDF files are named "Statement xxxx.PDF" and created in the same folder as the macro workbook, but you can change this to a specific folder as shown in the code.
Code:
Public Sub Create_PDFs()

    Dim dataValidationCell As Range, dataValidationListSource As Range, dvValueCell As Range
    Dim dropdownValue As String
    Dim PDFfile As String, i As Long
    Dim destinationFolder As String
    
    destinationFolder = ThisWorkbook.Path     'Same folder as workbook containing this macro
    'destinationFolder = "C:\path\to\folder\"  'Or specific folder
    
    If Right(destinationFolder, 1) <> "\" Then destinationFolder = destinationFolder & "\"
         
    'Cell containing data validation in-cell dropdown
    
    Set dataValidationCell = Worksheets("Statement").Range("E2")
     
    'Source of data validation list
    
    Set dataValidationListSource = Evaluate(dataValidationCell.Validation.Formula1)
     
    'Create PDF for each data validation value
    
    For Each dvValueCell In dataValidationListSource
        dataValidationCell.Value = dvValueCell.Value
        With dataValidationCell.Worksheet
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:=destinationFolder & "Statement " & dvValueCell.Value & ".PDF", _
                Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        End With
    Next
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,922
Messages
6,175,384
Members
452,639
Latest member
RMH2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top