save as pdf

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I need a procedure to save a document as pdf. The default file name needs to be the value that is entered in cell G7 + value entered in H5 as one word.

Could someone help me with this please?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
.
Code:
Option Explicit


Sub Export_Worksheet_to_PDF()
   
    Dim currentSheet As Worksheet, fname As String
    fname = ActiveSheet.Range("G7").Value & ActiveSheet.Range("H5").Value    '" for " & ActiveSheet.Range("H5").Value
    
    With ThisWorkbook
        Set currentSheet = .ActiveSheet
        .ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & fname & ".pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
    End With


End Sub


Saves the PDF file to the same location as the workbook. It selects the ACTIVE SHEET to convert to PDF.
 
Upvote 0
Try

Code:
Sub savepdf()
Dim sPath As String, sFile As string
sPath = ThisWorkbook.Path & "\"
sFile = range("g7") & range("h5")
Activeworkbook.ExportAsFixedFormat _
    Type:=x1typePDF, _
    Filename:=spath & sFile, _
    Quality:=xlQualityStandard, _
    Includedocproperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=false
End Sub
 
Upvote 0
Logit, your code just seems to work, but I need it to ask you where the file is to be saved instead of just being saved in the directory that the spreadsheet is located it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
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