hotspot1972
New Member
- Joined
- Jul 9, 2020
- Messages
- 16
- Office Version
- 2013
- Platform
- 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
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