Need help saving PDF name as the file's name

CRichards

New Member
Joined
Nov 24, 2014
Messages
4
Hello,

I am super super new to VBA. My boss wanted me add a macro to a file where certain tabs are selected and create a PDF. Looked it up and I'm good there.. Now I need help just saving the file as the excel file name (excluding the excel ending)...

This is what I'm working with.

Sub ExportAsPDF()


Dim FolderPath As String


FolderPath = "Z:\Analysis\_PDF\Filename"



Sheets(Array("Executive Summary", "Approval", "PA - Summary", "BA")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderPath, _
openafterpublish:=True, ignoreprintareas:=False

MsgBox "All PDF's have been successfully exported."


End Sub

The file name keeps on being called "Filename". I want this to be called the name of the excel file (excluding the excel ending).


Thank you!!!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this:

Code:
Sub ExportAsPDF()
  ' note the trailing \:
  Const sPath       As String = "Z:\Analysis\_PDF\"
  Dim sFile         As String

  With ActiveWorkbook
    sFile = Left(.Name, InStrRev(.Name, ".")) & "pdf"
    .Sheets(Array("Executive Summary", "Approval", "PA - Summary", "BA")).Select
  End With
  
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                  Filename:=sPath & sFile, _
                                  OpenAfterPublish:=True, _
                                  IgnorePrintAreas:=False

  MsgBox "All PDFs have been successfully exported."
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,843
Members
449,193
Latest member
MikeVol

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