I'm trying to save a workbook in a specific format, year and month ("YYYY_MM"). September 2011 would appear as "2011_09.xls"
I've written a macro to create the directory and save the file, however my month is only a single digit ("2011_9"). How can I get the month to appear as 2 digits for single digit months?
If Len(Dir("c:\test\", vbDirectory)) = 0 Then
MkDir "c:\test\"
End If
If Len(Dir("c:\test\" & Year(Range("A1")), vbDirectory)) = 0 Then
MkDir "c:\test\" & Year(Range("A1"))
End If
If Len(Dir("c:\test\" & Year(Range("A1")) & "\" & MonthName(Month(Range("A1")), True) & " " & Year(Range("A1")), vbDirectory)) = 0 Then
MkDir "c:\test\" & Year(Range("A1")) & "\" & MonthName(Month(Range("A1")), True) & " " & Year(Range("A1"))
End If
ActiveWorkbook.SaveAs Filename:="C:\test\" & Year(Range("A1")) & "\" & MonthName(Month(Range("A1")), True) & " " & Year(Range("A1")) & "\" & Year(Range("A1")) & "_" & Month(Range("a1")) & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Bookmarks