VBA to convert pdf

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
165
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi Excel Experts.
I want to save excel sheet as pdf, file name is as per cell C15, location -desktop.
Thank you
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Code:
Sub Maybe_So()
Dim myDir As String, i As Long
myDir = "C:\Abduls PDF Files\"    '<---- Change as required
    With ThisWorkbook
        For i = 1 To .Worksheets.Count
            .Worksheets(i).ExportAsFixedFormat 0, myDir & .Worksheets(i).Cells(15, 3).Value & ".pdf"
        Next i
    End With
End Sub
It assumes that all print ranges have been set as you don't mention it.
 
Upvote 1
Why not just do File > Print and choose Microsoft Print to PDF, enter the file name and choose the location?
 
Upvote 0
Why not just do File > Print and choose Microsoft Print to PDF, enter the file name and choose the location?
Thanks for quick reply. there are so many sheets, so I want to save the time and create a button to save as pdf with C15 cell name.
 
Upvote 0
There are several suggested threads at the bottom of this one. Did you review any of them, or do your own search for using a command button to print sheet as pdf? This topic has been answered a gazillion times on the internet so there's really no need to write a new sub from scratch.
 
Upvote 0
As Micron suggested, there are lots of threads requesting help for the same, as it sounds anyway, problem.
In you first Post, you say that you want to "save excel sheet as pdf" which indicates a single sheet.
In your next Post you say "There are many sheets".
So what would be your next question?
 
Upvote 0
As Micron suggested, there are lots of threads requesting help for the same, as it sounds anyway, problem.
In you first Post, you say that you want to "save excel sheet as pdf" which indicates a single sheet.
In your next Post you say "There are many sheets".
So what would be your next question?
Thanks for reply, There are many sheets in a workbook, Every sheet has a File name at C15 cell. so, I want to save as pdf every sheet as per Name as cell C15. at a time all sheets or one by one sheet.
 
Upvote 0
Does the C15 Cell also have the path or just the filename, with or without extension as the extension is known as pdf?
Re "all sheets or one by one"
How will this be determined if it means that you might want to save a single sheet or all sheets or a certain amount of sheets?

BTW, you don't need to quote for me. I find it just extra clutter not needed at all.
 
Upvote 0
It assumes that all print ranges have been set as you don't mention it.
VBA Code:
'Sub CopyData()
  Dim ws As Worksheet
    For Each ws In Worksheets
    If ws.Name <> "Data" And ws.Name <> "Centre" Then ws.UsedRange.Offset(18).ClearContents
  Next ws
    Application.ScreenUpdating = False
    Dim bottomA As Long
    bottomA = Range("F" & Rows.Count).End(xlUp).Row
    Dim AccNum As Range
    For Each AccNum In Range("F2:F" & bottomA)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -4)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "C").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -3)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "D").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -2)
        Sheets(CStr(AccNum)).Cells(Rows.Count, "E").End(xlUp).Offset(1, 0) = AccNum.Offset(0, -1)
    Next AccNum
    Application.ScreenUpdating = True
ActiveWorkbook.Save

ActiveSheet.PageSetup.PrintArea = "$A$1:$E$" & Cells(Rows.Count, "B").End(xlUp).Row
Sorry for incomplete information. C15 cell is just file name. I use above code. This code copy data from "Data" sheet and other sheets. print area set from A to E column up to last used B column cell except "Data" and "Centre" sheets. I want to save all sheets as pdf except sheets namely "Data" and "Centre" sheets. I think you are understand what is my goal. Thanks once again.
 
Upvote 0

Forum statistics

Threads
1,215,894
Messages
6,127,619
Members
449,390
Latest member
joan12

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