Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I am tasked with the very tedious assignment of updating about 24 separate
Excel 2007 files every week which requi - Open File of Current Week - Update Cell B7 with Week Beginning Date - Update Cell D7 with Week Ending Date - Delete Contents of Cells A10:L20 which have been updated throughout the current week - Save the updated file with a new Name corresponding to the Next Week Beginning and Ending Dates The number of files is growing and I need to find a more expeditious method of updating this very mundane task. I have attempted to write a Macro, but have not been successful. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Here's an *untested* macro. Note that it requires some modification to fit
your particular situation. Hopefully it at least gives some basic ideas/guidance. '=============== Sub UpdateFiles() Dim StartWeek, EndWeek As Date Dim OldPath, NewPath, FileName, NewName As String With Application ..ScreenUpdating = False ..DisplayAlerts = False End With 'If Sunday is start of week, use weekday arguement of 1 'If Monday is start of week, use weekday arguement of 2 StartWeek = Date + 1 - WorksheetFunction.Weekday(Date, 2) EndWeek = Date + 7 - WorksheetFunction.Weekday(Date, 2) 'Where are the files to be updated? OldPath = "C:\Documents and Settings\My Documents\MyFolder\" 'Where are the the new files to be created at? (should be a different spot) NewPath = "C:\Documents and Settings\My Documents\NewFolder\" ' This line makes sure the path ends with a back slash If Right(OldPath, 1) < "\" Then OldPath = OldPath & "\" If Right(NewPath, 1) < "\" Then NewPath = NewPath & "\" FileName = Dir$(OldPath & "*.xls") Do While Len(FileName) 0 Workbooks.Open (OldPath & FileName) Range("B7") = StartWeek Range("D7") = EndWeek Range("A10:L29").ClearContents 'Define filename NewName = Left(FileName, 6) & Format(StartWeek, "yyyymmdd") & _ Format(EndWeek, "yyyymmdd") & ".xls" Workbooks(FileName).SaveAs NewPath & NewName Workbooks(NewName).Close FileName = Dir$() Loop With Application ..DisplayAlerts = True ..ScreenUpdating = True End With End Sub '====================== -- Best Regards, Luke M *Remember to click "yes" if this post helped you!* "Flintstone" wrote: I am tasked with the very tedious assignment of updating about 24 separate Excel 2007 files every week which requi - Open File of Current Week - Update Cell B7 with Week Beginning Date - Update Cell D7 with Week Ending Date - Delete Contents of Cells A10:L20 which have been updated throughout the current week - Save the updated file with a new Name corresponding to the Next Week Beginning and Ending Dates The number of files is growing and I need to find a more expeditious method of updating this very mundane task. I have attempted to write a Macro, but have not been successful. |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks Luke. . . You are a lot faster than me. This will take a little bit
of time for me to work though, but I will keep you posted. "Luke M" wrote: Here's an *untested* macro. Note that it requires some modification to fit your particular situation. Hopefully it at least gives some basic ideas/guidance. '=============== Sub UpdateFiles() Dim StartWeek, EndWeek As Date Dim OldPath, NewPath, FileName, NewName As String With Application .ScreenUpdating = False .DisplayAlerts = False End With 'If Sunday is start of week, use weekday arguement of 1 'If Monday is start of week, use weekday arguement of 2 StartWeek = Date + 1 - WorksheetFunction.Weekday(Date, 2) EndWeek = Date + 7 - WorksheetFunction.Weekday(Date, 2) 'Where are the files to be updated? OldPath = "C:\Documents and Settings\My Documents\MyFolder\" 'Where are the the new files to be created at? (should be a different spot) NewPath = "C:\Documents and Settings\My Documents\NewFolder\" ' This line makes sure the path ends with a back slash If Right(OldPath, 1) < "\" Then OldPath = OldPath & "\" If Right(NewPath, 1) < "\" Then NewPath = NewPath & "\" FileName = Dir$(OldPath & "*.xls") Do While Len(FileName) 0 Workbooks.Open (OldPath & FileName) Range("B7") = StartWeek Range("D7") = EndWeek Range("A10:L29").ClearContents 'Define filename NewName = Left(FileName, 6) & Format(StartWeek, "yyyymmdd") & _ Format(EndWeek, "yyyymmdd") & ".xls" Workbooks(FileName).SaveAs NewPath & NewName Workbooks(NewName).Close FileName = Dir$() Loop With Application .DisplayAlerts = True .ScreenUpdating = True End With End Sub '====================== -- Best Regards, Luke M *Remember to click "yes" if this post helped you!* "Flintstone" wrote: I am tasked with the very tedious assignment of updating about 24 separate Excel 2007 files every week which requi - Open File of Current Week - Update Cell B7 with Week Beginning Date - Update Cell D7 with Week Ending Date - Delete Contents of Cells A10:L20 which have been updated throughout the current week - Save the updated file with a new Name corresponding to the Next Week Beginning and Ending Dates The number of files is growing and I need to find a more expeditious method of updating this very mundane task. I have attempted to write a Macro, but have not been successful. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I save a 2007 ex file so another party can open with 2003 | Excel Discussion (Misc queries) | |||
Open, Save and close Excel 2007 file with a cmd command | Excel Discussion (Misc queries) | |||
Open & delete file using a macro | Excel Discussion (Misc queries) | |||
How to save file in a macro taking new name from cell contents? | Excel Discussion (Misc queries) | |||
How to set SAVE AS file name to equal A1 contents when rename file | Excel Discussion (Misc queries) |