Create PDF using VBA, referencing a cell with location & Name etc

Dazzybeeguy

Board Regular
Joined
Jan 6, 2022
Messages
72
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
When I run this it saves to the Location that's in cell Z2 but saved it with filename as FALSE, any ideas what's wrong with my code ???

In cell Z2 it has location with filename at the end which will show current date "C:\Users\me\Documents\File Name 19-01-23.pdf"

Sub Create_Shift_PDF()
'
' Create_Shift_PDF Macro
' Will Save Current Data as a PDF Form
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
saveLocation = Sheets("Shift Brief").Range("z2").Value _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this
VBA Code:
Sub Create_Shift_PDF()
'
' Create_Shift_PDF Macro
' Will Save Current Data as a PDF Form
'
        Dim wk As Worksheet
        Set wk = ActiveSheet
        wk.ExportAsFixedFormat Type:=xlTypePDF, _
        FileName:=Sheets("Shift Brief").Range("z2").Value _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
End Sub
 
Upvote 0
Try this
VBA Code:
Sub Create_Shift_PDF()
'
' Create_Shift_PDF Macro
' Will Save Current Data as a PDF Form
'
        Dim wk As Worksheet
        Set wk = ActiveSheet
        wk.ExportAsFixedFormat Type:=xlTypePDF, _
        FileName:=Sheets("Shift Brief").Range("z2").Value _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
End Sub
Hi, It still saves with filename as of False
 
Upvote 0
do you have any value in range("Z2") in sheet shift brief?
Is the path where you're saving file is correct?
Are you sure you're looking at the newer copy of the pdf file instead of an older copy?
This is how it'd look in documents folder
1674137679384.png
 
Upvote 0
do you have any value in range("Z2") in sheet shift brief?
Is the path where you're saving file is correct?
Are you sure you're looking at the newer copy of the pdf file instead of an older copy?
This is how it'd look in documents folder
View attachment 83194
In Z2 it has the location it will be saved to with the name which will include date & time i.e "C:\Users\me\Documents\File Name 19-01-23.pdf

When I run the code I tried it saves it to the given location but filename is FALSE
 
Upvote 0
If this doesn't work then idk.
VBA Code:
Sub Create_Shift_PDF()
'
' Create_Shift_PDF Macro
' Will Save Current Data as a PDF Form
'
        Dim wk As Worksheet
        Set wk = ActiveSheet
        Dim FilePath As String
        FilePath = Sheets("Shift Brief").Range("z2")
        
        wk.ExportAsFixedFormat Type:=xlTypePDF, _
        FileName:=FilePath _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,545
Members
449,316
Latest member
sravya

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