Macro to print mutliple sheets i choose to PDF

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
Maybe you can help?

I have a document

I want to print out the sheets i select

all pages are set up with print areas etc.

so heres what i need?

I have a list of all my sheet names down column H

In column J I have have all the sheets i want to print maked with an "a"

so i need a macro that can go down column H and if Column J of that row is an "a" mark it to be printed

then once it has all the sheets it wants to print selected, it create a PDF call "value of K12" and saved in the same folder we are currently in.

please help if you can thanks

Tony
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Change in the macro "Master" by the name of your sheet with the names of all the sheets.

Try this:

VBA Code:
Sub SavePdf()
  Dim sName As String, sPath As String
  Dim i As Long, sh As Worksheet, bSel As Boolean
  
  Set sh = Sheets("Master")
  bSel = True
  For i = 1 To sh.Range("H" & Rows.Count).End(3).Row
    If LCase(sh.Range("J" & i).Value) = LCase("a") Then
      sName = sh.Range("H" & i).Value
      If Evaluate("ISREF('" & sName & "'!A1)") Then
        Sheets(sName).Select Replace:=bSel
        bSel = False
      End If
    End If
  Next
  
  sPath = ThisWorkbook.Path & "\" & "value of K12.pdf"

  ActiveSheet.ExportAsFixedFormat xlTypePDF, sPath, xlQualityStandard, True, False, , , False
  Sheets(1).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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