Help needed saving a worksheet as PDF into new created dated folder

hotspot1972

New Member
Joined
Jul 9, 2020
Messages
16
Office Version
  1. 2013
Platform
  1. Windows
Hi. Ive created a button to save a backup of a worksheet into a specific path/folder.
I want to create a "NEW" folder with todays date - then save the backup (as PDF) in that newly created folder.
The code i has - creates the folder ok - but does not save the worksheet in that new dated folder - rather outside it.
Any help please?
heres my current code:

Sub SaveTodayFile()

Dim sPath As String
Dim sFileName As String
Dim TodayDate As String
Dim time As String


Application.DisplayAlerts = False
time = Format(Now, "hh.mm.ss")
TodayDate = Format(Date, "dd-mm-yyyy")
sPath = "L:\BabyCare\22. Robots\26. Morning links\DDS Sheet\Wrapper Parameter Archive\" & TodayDate
sFileName = "SW3 Program 3" & " _ " & time & ".pdf"

On Error GoTo myerror
If Dir(sPath, vbDirectory) = vbNullString Then MkDir sPath

Application.Wait (Now + TimeValue("00:00:04"))

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFileName

myerror:
Application.DisplayAlerts = True
If Err > 0 Then MsgBox (Error(Err)), 16, "Error"
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

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