Saving as Pdf In a specified folder

Ernest Ansah

New Member
Joined
Oct 12, 2022
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
Hello .. please kindly help me with a macro that can save a sheet as pdf using a cell range and the date below are the codes
saveLocation = "C:\Users\Public\Documents" \ "BS-2TERM 1 " & Range("b5") & Format(DateTime.Now, "-yyyy-MM-dd hh-mm-ss") & ".pdf"
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Ernest Ansah,

maybe try
VBA Code:
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                  Filename:="C:\Users\Public\Documents" \ "BS-2TERM 1 " & Range("b5") & Format(Now, "-yyyy-MM-dd hh-mm-ss") & ".pdf", _
                                  Quality:=xlQualityStandard, _
                                  IncludeDocProperties:=True, _
                                  IgnorePrintAreas:=False, _
                                  OpenAfterPublish:=False
Ciao,
Holger
 
Upvote 0
This is the code but there are still errors


Private Sub cbSaveAsPDF()
Dim sPath As String
Dim sFile As Variant
Dim ws As Worksheet
Dim Filename As String
On Error GoTo ErrHandle

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\Public\Documents" \ "BS-2TERM 1 " & Range("b5") & Format(Now, "-yyyy-MM-dd hh-mm-ss") & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False



ErrHandle:
MsgBox ("Document Not Saved")


End Sub
 
Upvote 0
Hi Ernest Ansah,

one I did not realize when pasting in the code for the path and one for not leaving the sub before the error handling:

VBA Code:
Private Sub cbSaveAsPDF()

On Error GoTo ErrHandle

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="C:\Users\Public\Documents\BS-2TERM 1 " & Range("b5") & Format(Now, "-yyyy-MM-dd hh-mm-ss") & ".pdf", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

'leaving here when no error had occurred
Exit Sub

'only in case an error was raised
ErrHandle:
MsgBox ("Document Not Saved")

End Sub
Ciao,
Holger
 
Upvote 0
Hi Ernest Ansah,

one I did not realize when pasting in the code for the path and one for not leaving the sub before the error handling:

VBA Code:
Private Sub cbSaveAsPDF()

On Error GoTo ErrHandle

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="C:\Users\Public\Documents\BS-2TERM 1 " & Range("b5") & Format(Now, "-yyyy-MM-dd hh-mm-ss") & ".pdf", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

'leaving here when no error had occurred
Exit Sub

'only in case an error was raised
ErrHandle:
MsgBox ("Document Not Saved")

End Sub
Ciao,
Holger
Its working Perfectly .. thanks a lot Senior.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,210
Members
448,554
Latest member
Gleisner2

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