Wednesday, 26 September 2012

How To Create a Folder and a Excel File By Current Date And Time

Macro To Create a Folder and a Excel File By Current Date And Time
'We can use this Macro To Save Dalily Tasks from 'Regular Task Workbook' to a WorkBook with Current Date & Time

Sub CrtTaskShtByToday()

Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim e As String


On Error Resume Next
Application.DisplayAlerts = False

A = Day(Date) 'Day Value From Date
B = Month(Date) 'Month Value From Date
C = Year(Date) 'Year Value From Date
E = A & "-" & B & "-" &C

MkDir "D:\MyXlProjects\" & e 'Make a Desired Folder By Current Date & Time

Workbooks(e).Close

Workbooks.Add.SaveAs ("D:\MyXlProjects\" & E & "\" & E & ".xlsx")
'A Folder & File with Current Date& Time will be created

Workbooks("MainTask").Activate
ActiveWorkbook.ActiveSheet.Cells.Copy Workbooks(e).Sheets("Sheet1").Range("a1")
'Copy Data From Active Sheet to a Sheet1 of Newly Created Workbook

Workbooks(e).Save
Workbooks(e).Close

End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts