VBA to convert tabs to PDF if selected from cells

Gealer

New Member
Joined
Sep 19, 2018
Messages
19
Need to macro to convert selected tabs to PDF

Say in A1 to A10 is the tab name and the in B1 to B10 is true or false

If it is true in B1 to b10 then it will convert them to PDF
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this

Change data in red by your information. (Sheet with the names of the sheets, folder and name of pdf file).

Code:
Sub convert_tabs_PDF()
  Dim sh1 As Worksheet, sh As Worksheet, c As Range, shs() As Variant, n As Long
  Set sh1 = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
  n = 0
  For Each c In sh1.Range("A1", sh1.Range("A" & Rows.Count).End(xlUp))
    If c.Offset(, 1) Then
      For Each sh In Sheets
        If LCase(sh.Name) = LCase(c.Value) Then
            ReDim Preserve shs(n)
            shs(n) = sh.Name
            n = n + 1
            Exit For
        End If
      Next
    End If
  Next
  If n > 0 Then
    Sheets(shs).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=[COLOR=#ff0000]ThisWorkbook.Path & "\file.pdf"[/COLOR], _
      Quality:=xlQualityStandard, OpenAfterPublish:=False
    sh1.Select
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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