Save as PDF in the same location of Source File path

MHD

New Member
Joined
Mar 16, 2021
Messages
49
Office Version
  1. 2019
This a test code but the result not what I need!
The result looks like this: (Desktop Filename.pdf)

Private Sub Image_PDF_Click()
'save as PDF

Dim File_name As String
Dim thisWb As Workbook
Set thisWb = ActiveWorkbook
File_name = thisWb.Path & Worksheets("Lists & File Name").Range("C45").Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
thisWb.Path & "File_name", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

MsgBox ("Done!")
End Sub



Any advice, please!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
When thisWb.Path returns the path, it doesn't include the backslash ( \ ) at the end of it. So, assuming that the value in cell C45 contains the filename, but doesn't include the backslash at the beginning, try...

VBA Code:
File_name = thisWb.Path & "\" & Worksheets("Lists & File Name").Range("C45").Value

Then save the PDF as follows...

VBA Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=File_name, Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Hope this helps!
 
  • Like
Reactions: MHD
Upvote 0
Solution

Forum statistics

Threads
1,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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