Save a specific range of excel sheet in pdf format in a new folder

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Welcome. I want to create a new folder, name it and save a specific excel sheet. Include it in pdf format in the same path as the main file.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I asked an AI website your question. The response received (untested) :

Sure, here's some VBA code that should accomplish what you're looking for:

VBA Code:
Sub SaveAsPDF()
' Get the path of the current workbook
Dim path As String
path = ThisWorkbook.Path & "\"
' Create a new folder with the current date and time as the name
Dim folderName As String
folderName = Format(Now(), "yyyy-mm-dd_hh-mm-ss")
MkDir path & folderName
' Save the current worksheet as a PDF in the new folder
Dim fileName As String
fileName = folderName & "\" & "MyWorksheet.pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & fileName
' Display a message box to confirm the save
MsgBox "PDF saved in folder: " & path & folderName
End Sub

This code will create a new folder in the same path as the current workbook, using the current date and time as the folder name. It will then save the current worksheet as a PDF in that folder, with the filename "MyWorksheet.pdf". Finally, it will display a message box to confirm that the PDF has been saved.

You can modify the code to change the folder name or PDF filename to whatever you like. If you want to save a different worksheet, you'll need to modify the `ActiveSheet` reference to point to the worksheet you want to save.
 
Upvote 0
Solution
I asked an AI website your question. The response received (untested) :

Sure, here's some VBA code that should accomplish what you're looking for:

VBA Code:
Sub SaveAsPDF()
' Get the path of the current workbook
Dim path As String
path = ThisWorkbook.Path & "\"
' Create a new folder with the current date and time as the name
Dim folderName As String
folderName = Format(Now(), "yyyy-mm-dd_hh-mm-ss")
MkDir path & folderName
' Save the current worksheet as a PDF in the new folder
Dim fileName As String
fileName = folderName & "\" & "MyWorksheet.pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path & fileName
' Display a message box to confirm the save
MsgBox "PDF saved in folder: " & path & folderName
End Sub

This code will create a new folder in the same path as the current workbook, using the current date and time as the folder name. It will then save the current worksheet as a PDF in that folder, with the filename "MyWorksheet.pdf". Finally, it will display a message box to confirm that the PDF has been saved.

You can modify the code to change the folder name or PDF filename to whatever you like. If you want to save a different worksheet, you'll need to modify the `ActiveSheet` reference to point to the worksheet you want to save.
Thank you very much. Really this is what is needed and it works very well
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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