Save sheets from query to seperate Pdf Files choose location

Dedeke

Board Regular
Joined
Dec 1, 2020
Messages
70
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, (surtenly Fluff;))

I have been reading a lot over here about saving sheet to pdf but still did not came to solution.
So i have a sheet called "Data".
Depending on colum C i run a query which is displayed on the same sheet"Data"
Now i only want to print the sheets of query result.
Info: If name in colum A changes also the sheetname changes in same way.
What i got this far( found and used from this forum) is this code which print all of my sheets.
Any solution would be great and helpfull.

Thx already

VBA Code:
Sub Exportalltopdf()


Dim Folder_Path As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Selecteer de gewenste folder"

If .Show = -1 Then Folder_Path = .SelectedItems(1)
End With

Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
 sh.ExportAsFixedFormat xlTypePDF, Folder_Path & Application.PathSeparator & sh.name & ".pdf"
 Next
 
 MsgBox " Files saved"

End Sub
 

Attachments

  • Only query as pdf.JPG
    Only query as pdf.JPG
    79.4 KB · Views: 3

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
sorry for all off your time,

Found a solution saving separate pdf from sheets depending on a cell value on each sheet.
Used following code:

VBA Code:
Public Sub Create_PDFs()
  'To choose where to save the file'
Dim Folder_Path As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Selecteer de gewenste folder"

If .Show = -1 Then Folder_Path = .SelectedItems(1)

End With
  'To veryfy if cell D5 on each sheet has the value "P" or "D" if so save them'
    Dim ws As Worksheet
    
    For Each ws In ActiveWorkbook.Worksheets
            If ws.Range("D5").Value = "P" Then
                ws.ExportAsFixedFormat xlTypePDF, Folder_Path & Application.PathSeparator & ws.Name & ".pdf"
            Else
            If ws.Range("D5").Value = "D" Then
                ws.ExportAsFixedFormat xlTypePDF, Folder_Path & Application.PathSeparator & ws.Name & ".pdf"
            Else
    End If
    End If
    Next
    MsgBox "All saved I guess"

End Sub

This on saves all my sheets from "P" pilots and "D" duo's
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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