Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Batch Open and Save

Hi
I have a really simple need: some code to open all xls files in a
specified directory and then save the files with a modified name (e.g.
just add "_fm" to filename)to a new subdir. In between the open and
save I will insert some code to do some simple formatting but really
would appreciate some help in opening a bunch of files and then saving
them.
Thanks
James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Batch Open and Save

dim spath1 as string, spath2 as string, fname as string
Dim fname1 as string, wkbk as workbook
spath1 = "C:\Myfiles\"
sPath2 = "C:\MyfilesNew\"

fname = dir(sPath1 & "*.xls")
do while fname < ""
set wkbk = workbooks.Open(fname)
' modify workbook, next line is an example
wkbk.Worksheets(1).Range("A1").Numberformat = "#,##0.0"
' no build the new name
fname1 = wkbk.name
fname1 = left(fName1,len(fname1)-4)
fname1 = fname1 & "_fm.xls"
wkbk.SaveAs sPath2 & fname1
wkbk.close SaveChanges:=False
fName = dir()
Loop

code is untested and may contain typos.
--
Regards,
Tom Ogilvy

"James" wrote in message
om...
Hi
I have a really simple need: some code to open all xls files in a
specified directory and then save the files with a modified name (e.g.
just add "_fm" to filename)to a new subdir. In between the open and
save I will insert some code to do some simple formatting but really
would appreciate some help in opening a bunch of files and then saving
them.
Thanks
James



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
whenever open or save it is very slow to open Nav J Excel Discussion (Misc queries) 1 August 13th 09 02:32 PM
run batch job from each row - how to insert run batch function per row? Mitchell_Collen via OfficeKB.com Excel Discussion (Misc queries) 5 February 26th 09 07:16 AM
batch file to open multiple worksheets Kurt S Excel Discussion (Misc queries) 4 June 12th 06 07:45 PM
save prompt for user exit, but no save prompt for batch import? lpj Excel Discussion (Misc queries) 1 February 25th 06 02:08 AM
How can I batch open a txt file in excel 2003 and save back as a . P Silzle Excel Discussion (Misc queries) 3 February 9th 05 11:44 PM


All times are GMT +1. The time now is 06:39 AM.

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

About Us

"It's about Microsoft Excel"