Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default 2007 Macro to Open File, Delete Contents, Save New File

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default 2007 Macro to Open File, Delete Contents, Save New File

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22
Default 2007 Macro to Open File, Delete Contents, Save New File

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I save a 2007 ex file so another party can open with 2003 Mel Excel Discussion (Misc queries) 2 September 14th 08 11:00 PM
Open, Save and close Excel 2007 file with a cmd command Hugo Pinto Excel Discussion (Misc queries) 5 March 3rd 08 10:05 PM
Open & delete file using a macro Dode Excel Discussion (Misc queries) 3 December 5th 07 07:25 PM
How to save file in a macro taking new name from cell contents? LowIQ Excel Discussion (Misc queries) 3 May 31st 06 10:52 PM
How to set SAVE AS file name to equal A1 contents when rename file E Excel Discussion (Misc queries) 0 October 19th 05 08:36 PM


All times are GMT +1. The time now is 04:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"