ExportasFixedFormat not following path

Claire Jackson

Board Regular
Joined
Jun 30, 2020
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
I've got the following code but when the PDF is saved it's not saving to the correct folder and its using "SaveLocationFilename!" as the file name?

Sub Save_As_PDF()

Dim SaveLocation As Range
Dim Filename1 As Range

Set SaveLocation = Workbooks("Test Form with CRM Data.xlsm").Worksheets("Sheet1").Range("$L$13")
Set Filename1 = Workbooks("Test Form with CRM Data.xlsm").Worksheets("Sheet1").Range("$L$6")

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="SaveLocation" & "Filename1", OpenAfterPublish:=True

MsgBox "File Saved to" & " " & Filename1


End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You need to remove the quotes from your variables, otherwise they are strings
VBA Code:
 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SaveLocation & Filename1, OpenAfterPublish:=True
 
Upvote 0
Thanks but now I get a run time error '2147024773 (8007007b)': Document not saved?

It's pulling from here with L13 as the path and L6 as the filename?

1600084778081.png
 
Upvote 0
its a date but I want it to use it as the file name? Its coming from the formula =now()

I did print.debut and it's stopping at Type:=xlTypePDF
 
Upvote 0
Ok, how about
VBA Code:
Sub Save_As_PDF()

Dim SaveLocation As String
Dim Filename1 As String

With Workbooks("Test Form with CRM Data.xlsm").WorkSheets("Sheet1")
   SaveLocation = .Range("$L$13").Value
   Filename1 = .Range("$L$6").Text
End With

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=SaveLocation & "\" & Filename1, OpenAfterPublish:=True

MsgBox "File Saved to" & " " & SaveLocation & "\" & Filename1


End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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