Craig_Moore
Board Regular
- Joined
- Dec 12, 2018
- Messages
- 64
- Office Version
- 2019
- Platform
- Windows
Hi ALL
I have the below code which works great, but i was wondering if there was a way for the code to create a year folder and then a month folder then save the workbook the correct amount of times in to each moth folder?
any help would be welcome
Thanks
Craig
I have the below code which works great, but i was wondering if there was a way for the code to create a year folder and then a month folder then save the workbook the correct amount of times in to each moth folder?
any help would be welcome
Thanks
Craig
VBA Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim sFilename As Variant
Dim sName As String
Dim sExtension As String
Dim dDate As Date
Dim nLeapYear As Integer
Dim n As Integer 'date counter
Dim worksheets As String
' line below re hides the vba download before saving the file
ThisWorkbook.worksheets("VBA DOWNLOAD").Visible = xlSheetVeryHidden
sFilename = Application.GetSaveAsFilename(fileFilter:=".xlsm (*.xlsx; *.xlsm), *.xlsx; *.xlsm")
If sFilename <> "" Then
sName = Left(sFilename, InStr(sFilename, ".") - 1)
sExtension = Right(sFilename, Len(sFilename) - Len(sName))
dDate = Range("START_DATE").Value
If MsgBox("Is this a leapyear?", vbYesNo) = vbYes Then
nLeapYear = 1
Else
nLeapYear = 0
End If
'line below refers to cell in vba download sheet change cell value to quantity of saves total including fisrt date
For n = 1 To Range("DATE_COUNT").Value
sFilename = Format(dDate, "dd-mm-YY")
Application.StatusBar = " Exporting File Dated: " & dDate
ActiveWorkbook.SaveAs Filename:=sFilename
dDate = dDate + 1
Application.ScreenUpdating = True
Next n
End If
Application.StatusBar = "SAVE HAS COMPLETED"
End Sub