I am trying to rename a PDF that has been exported from a workbook.

Mwill15g

New Member
Joined
Jan 14, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I have the following code in place now but instead of overwriting the pdf in the file location I want to add a date to the name. That way I can go back and see previous file that have been ran before. I am completely green to this so any help or advise would be welcomed.

ChDir "S:\WWWW\To_MdSt"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

"S:\WWWW\To_MdSt\XXXX\OOOO", Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _

True
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

BigDawg15

Board Regular
Joined
Apr 23, 2018
Messages
56
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try this:
VBA Code:
ChDir "S:\WWWW\To_MdSt"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

"S:\WWWW\To_MdSt\XXXX\OOOO" & format(Date, " mm-dd-yyyy") & ".pdf", Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _

True
 
Solution

Mwill15g

New Member
Joined
Jan 14, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
@BigDawg15 Nailed it! It worked perfect! I have been playing around with this for way too long! Appreciate it! GoVols!
 

BigDawg15

Board Regular
Joined
Apr 23, 2018
Messages
56
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Go Vols! That's cute. Lol. Thanks for the feedback.
 

Mwill15g

New Member
Joined
Jan 14, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Try this:
VBA Code:
ChDir "S:\WWWW\To_MdSt"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

"S:\WWWW\To_MdSt\XXXX\OOOO" & format(Date, " mm-dd-yyyy") & ".pdf", Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _

True
Try this:
VBA Code:
ChDir "S:\WWWW\To_MdSt"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _

"S:\WWWW\To_MdSt\XXXX\OOOO" & format(Date, " mm-dd-yyyy") & ".pdf", Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _

True
Quick question, if I wanted to export it as an excel instead of a PDF what would I need to change?
 

BigDawg15

Board Regular
Joined
Apr 23, 2018
Messages
56
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try:

VBA Code:
Sub SaveSheet()
ActiveSheet.Copy
With ActiveSheet.UsedRange
.Copy
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With
Application.CutCopyMode = False
Dim DTAddress As String
DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
ActiveWorkbook.SaveAs DTAddress & Range("E19") & " " & Format(Date, "mmmmddyyyy") & " " & Format(Time, "HHMM"), FileFormat:= _
xlNormal
End Sub
 

BigDawg15

Board Regular
Joined
Apr 23, 2018
Messages
56
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Something like this:

VBA Code:
Activesheet.Copy   'creates an independent copy of the activesheet
 
Activeworkbook.SaveAs "C:\SomeFolder\SomeFileName.xls", FileFormat:=xlWorkbookNormal   'save workbook created above
 
Activeworkbook.Close  'close it and return to original workbook
 

Forum statistics

Threads
1,176,138
Messages
5,901,574
Members
434,906
Latest member
Prabhu_Churi

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
Top