VBA to convert tabs to PDF if selected from cells

Gealer

New Member
Joined
Sep 19, 2018
Messages
12
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
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
10,243
Office Version
2007
Platform
Windows
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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
10,243
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,090,138
Messages
5,412,687
Members
403,441
Latest member
speedtobeat

This Week's Hot Topics

Top