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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,889
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
8,889
Office Version
2007
Platform
Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,082,306
Messages
5,364,410
Members
400,801
Latest member
julievandermeulen

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top