Results 1 to 3 of 3

Saving a Workbook by Month

Threaded View

Ricker090 Saving a Workbook by Month 08-14-2011, 07:34 PM
p24leclerc Re: Saving a Workbook by Month 08-14-2011, 08:44 PM
Ricker090 Re: Saving a Workbook by Month 08-14-2011, 09:07 PM
  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Saving a Workbook by Month

    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
    Attached Files Attached Files
    Last edited by Ricker090; 08-14-2011 at 09:09 PM. Reason: Solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1