Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Opening a list of workbooks with vba, similar to going through sheets in a workbook?

Hi guys,

Can I go through (1 by 1) a series of workbooks in the same folder just as
I can go through a series of worksheets one by one in a workbook.

I have a spreadsheet for every day (about 6 months worth) and each
individual workbook is named something like thur-13-apr.

I need to open each in turn and do some changes to them all. The changes
can be done with vba as they are all formatted the same inside but I want
to open each with a macro (if possible) and then close when the work is
done.

I don't want to have to open each manually if possible.

Is this possible?

Ron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Opening a list of workbooks with vba, similar to going through sheets in a workbook?

You'll have to open each workbook in order to make changes. Use
code like

Dim FName As Variant
Dim WB As Workbook
ChDrive "H:" '<<< CHANGE
ChDir "H:\Test" '<<< CHANGE
FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(FName)
Debug.Print WB.Name
' work with WB
WB.Close savechanges:=True
FName = Dir()
Loop


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Ron" wrote in message
...
Hi guys,

Can I go through (1 by 1) a series of workbooks in the same
folder just as
I can go through a series of worksheets one by one in a
workbook.

I have a spreadsheet for every day (about 6 months worth) and
each
individual workbook is named something like thur-13-apr.

I need to open each in turn and do some changes to them all.
The changes
can be done with vba as they are all formatted the same inside
but I want
to open each with a macro (if possible) and then close when the
work is
done.

I don't want to have to open each manually if possible.

Is this possible?

Ron



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Opening a list of workbooks with vba, similar to going through she

Dim sName as String, v as Variant
Dim bOK as Boolean, i as Long
Dim bk as Workbook
sName = Dir("C:\Myfiles\" & "*.xls")
v = Array("Jan","Feb","Mar","Apr","May","Jun", _
"Jul","Aug","Sep","Oct","Nov",Dec")
do while sname < ""
bOK = False
for i = lbound(v) to ubound(v)
if Instr(1,sName,v(i) & "-",vbTextCompare) 0 then
bOK = True
exit for
end if
Next
if bOk then
set bk = workbooks.Open("C:\Myfiles\" & sName)
' process bk
bk.Close Savechanges:=True
end if
sName = Dir()
Loop


--
Regards,
Tom Ogilvy

"Ron" wrote:

Hi guys,

Can I go through (1 by 1) a series of workbooks in the same folder just as
I can go through a series of worksheets one by one in a workbook.

I have a spreadsheet for every day (about 6 months worth) and each
individual workbook is named something like thur-13-apr.

I need to open each in turn and do some changes to them all. The changes
can be done with vba as they are all formatted the same inside but I want
to open each with a macro (if possible) and then close when the work is
done.

I don't want to have to open each manually if possible.

Is this possible?

Ron

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Opening a list of workbooks with vba, similar to going through she

Thanks Chip & Tom. I appreciate the swift response.

Ron



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
Copy data from diff workbooks but without opening sheets raja Excel Programming 1 September 21st 05 02:21 PM
comparing 2 similar columns on seperate work sheets in 1 workbook Dan Excel Discussion (Misc queries) 4 September 20th 05 11:58 PM
Opening a list of workbooks Barb Reinhardt Excel Programming 3 August 27th 05 02:22 AM
How can I delete similar rows in excel workbook with many sheets? JSchrader Excel Worksheet Functions 1 April 26th 05 06:40 PM
How do you list all the workbooks you have opened and the sheets in each workbook? Wendy[_3_] Excel Programming 1 December 5th 03 09:17 PM


All times are GMT +1. The time now is 09:41 AM.

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"