Good day everyone,
I have a unique VBA issue (or so I think I do). I have a workbook that will print multiple worksheets within it to a single PDF file. However, not every file needs to be printed, and to determine if the page should printed is based on the value of one cell. Here's what my code looks like:
What this code currently does, is it will print each lab's information to a PDF file for me which I send out to the labs for review. However, the code prints all 132 labs (including the blanks) rather than just the labs with information. I want to skip the empty files and print only the ones containing information. But I run into an issue when printing to PDF, it prints every lab even if the lab's file is empty. I just want to skip the empty files and print the ones containing information. Any help is greatly appreciated! Thank you!
I have a unique VBA issue (or so I think I do). I have a workbook that will print multiple worksheets within it to a single PDF file. However, not every file needs to be printed, and to determine if the page should printed is based on the value of one cell. Here's what my code looks like:
VBA Code:
Sub PrintPDF2()
' PrintPDF2 Macro
' Keyboard Shortcut: Ctrl+p
' Make sure Indv Rep is on the lab number you want to start with or the code won't generate the PDF files necessary
Dim num As Integer
Dim x As Integer
For num = 1 To 132
Sheets("Indv Rep").Select
Range("A1:k63").Select
' The first line indicates which labs you are printing. Make sure you have cell A1 selected in your worksheet and the
'range above always begins at A1 and ends where the data on the INDV REP page stops
x = num
Selection.Replace what:="$" & num, Replacement:="$" & num + 1, LookAt:=xlPart, _
Searchorder:=xlByRows, MatchCase:=False
If Range("f7").Value <> "0" Then
Sheets(Array("indv rep", "chart1", "chart2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"X:\YY\Proficiency Sample Program\ZZ\XXYY\Final\Lab " & Worksheets("Indv Rep").Range("A1").Value & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next num
Selection.Replace what:="$" & x + 1, Replacement:="$2", LookAt:=xlPart, _
Searchorder:=xlByRows, MatchCase:=False
End Sub
What this code currently does, is it will print each lab's information to a PDF file for me which I send out to the labs for review. However, the code prints all 132 labs (including the blanks) rather than just the labs with information. I want to skip the empty files and print only the ones containing information. But I run into an issue when printing to PDF, it prints every lab even if the lab's file is empty. I just want to skip the empty files and print the ones containing information. Any help is greatly appreciated! Thank you!