Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Adding Week Commencing Date to filename

$
0
0

I have a macro that generates 17 different workbooks. I will paste the code below for one of the workbook generations. What I want to do is that when this macro is run, I want it to look at the date run, and then add the date for the following Monday to the filename automatically, so for as in the example code I am pasting in it would create a file called '13-Coastal-Route-wc-01072013'.xlsx 

    Application.DisplayAlerts = False
    Workbooks.Add
    ChDir "W:\MAINTENANCE\Reference_Files"
    ActiveWorkbook.SaveAs Filename:="W:\MAINTENANCE\Reference_Files\13-Coastal-Route.xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Windows("Weekly Test Routes - June 2013.xls").Activate
    Sheets("13-Coastal").Select
    Columns("A:G").Select
    Selection.Copy
    Windows("13-Coastal-Route.xlsx").Activate
    ActiveSheet.Paste
    Range("H1").Select
    ActiveCell.FormulaR1C1 = "Engineer Notes"
    Range("A1").Select
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A12").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = False
        .ShowError = True
    End With
    Selection.Copy
    Range("A13:A200").Select
    ActiveSheet.Paste
    Range("A13").Select
    Application.CutCopyMode = False
    Range("A12").Select
    Range("B1").Select
    Selection.Cut Destination:=Range("C1")
    Columns("B:B").Select
    Selection.Cut
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight
    Range("E11").Select
    ActiveCell.FormulaR1C1 = "Notes"
    Range("A11").Select
    ActiveCell.FormulaR1C1 = "Completed"
    Range("A12").Select
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Range("A1").Select
    Application.CutCopyMode = False

Any help would be appreciated as always

Toni C


Toni Chaffin aka Talisa


Viewing all articles
Browse latest Browse all 11829

Trending Articles