Carla carla
Board Regular
- Joined
- Oct 29, 2022
- Messages
- 53
- Office Version
- 365
- Platform
- Windows
Hello,
The below is the macro code I am using to create pdf files from data validation list. My data validation is on cell B2. But I want the file name to save as A2. How can I add this condition in the existing macro?
Public Sub Create_PDFs()
Dim destinationFolder As String
Dim dataValidationCell As Range, dataValidationListSource As Range, dvValueCell As Range
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("test1").Range("B2")
'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.Range("A1:I45")
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=destinationFolder & dvValueCell.Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Next
End Sub
The below is the macro code I am using to create pdf files from data validation list. My data validation is on cell B2. But I want the file name to save as A2. How can I add this condition in the existing macro?
Public Sub Create_PDFs()
Dim destinationFolder As String
Dim dataValidationCell As Range, dataValidationListSource As Range, dvValueCell As Range
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("test1").Range("B2")
'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.Range("A1:I45")
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=destinationFolder & dvValueCell.Value & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Next
End Sub