Save to PDF (File Name To Equal Cell Value)

pauleapo

Board Regular
Joined
Nov 23, 2005
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have something already in use that saves an excel doc to a specific location with the filename based on a cells value.

I am wanting to do the same but printing/saving in a pdf, I can't figure out how I need to change the bottom line to save as pdf and not as xlsm, any help would be appreciated.

VBA Code:
Dim FName           As String
    Dim FPath           As String
     
    FPath = Sheets("Timber Programme").Range("W3").Text
    FName = Sheets("Timber Programme").Range("X3").Text
    ThisWorkbook.SaveAs Filename:=FPath & "\" & FName
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try:
VBA Code:
Sub SavePDF()
    Dim FName As String, FPath As String
    FPath = Sheets("Timber Programme").Range("W3").Value
    FName = Sheets("Timber Programme").Range("X3").Value
    Sheets.Select
    ChDir FPath
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
Try:
VBA Code:
Sub SavePDF()
    Dim FName As String, FPath As String
    FPath = Sheets("Timber Programme").Range("W3").Value
    FName = Sheets("Timber Programme").Range("X3").Value
    Sheets.Select
    ChDir FPath
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
End Sub

Thank you but this gives a compile error 'Duplicate declaration in current scope' and highlights FName As String
 
Upvote 0
Thank you but this gives a compile error 'Duplicate declaration in current scope' and highlights FName As String
That usually means that you have the
VBA Code:
Dim FName As String
line listed twice in your code.
Just remove one.
 
Upvote 0
That usually means that you have the
VBA Code:
Dim FName As String
line listed twice in your code.
Just remove one.

Brilliant, thanks, also had to remove Sheets.Select it now works and an absolute treat

Again thanks to you both
 
Upvote 0
You are very welcome. :) By removing that line of code, you are saving the active sheet only. In the quote below, I assumed you wanted to save the entire workbook.
saves an excel doc
 
Upvote 0
You are very welcome. :) By removing that line of code, you are saving the active sheet only. In the quote below, I assumed you wanted to save the entire workbook.

Sorry I didn't make it clear, yes I was only saving the worksheet. ?
 
Upvote 0
No problem as long as it all worked out. :)
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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