Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening multiple workbooks

Currently I have a mcro that opens up one workbook: -

Sub Macro1()
Workbooks.Open Filename:="C:\Data\Book2.xls"
End Sub

Can I make this Macro open all .xls files in the current Directory: -
Like

Sub Macro1()
Workbooks.Open Filename:="C:\Data\*.xls"
End Sub

Any ideas

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Opening multiple workbooks

Sub Macro1()
Dim sName as String
sName = Dir("C:\Data\*.xls")
do while sName < ""
Workbooks.Open Filename:=sName
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy


"ianripping " wrote in message
...
Currently I have a mcro that opens up one workbook: -

Sub Macro1()
Workbooks.Open Filename:="C:\Data\Book2.xls"
End Sub

Can I make this Macro open all .xls files in the current Directory: -
Like

Sub Macro1()
Workbooks.Open Filename:="C:\Data\*.xls"
End Sub

Any ideas?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Opening multiple workbooks

Tom & Ianripping,

This is just the code I've been looking for. It works great! I can add
wildcards to suit my macros, but I would like some more help with 2 problems
that are similar to the first.

My first macro is used to open about 50 *A*.csv files, formats and saves
each file as *A*.xls. Then it opens 50 *B*.csv files, and processes them
the same way. My problem is that the directory which holds the files
changes. Can I use "sName = Application.GetOpenFilename" with "*A*.csv"?
If not, how do I select a folder, and open multiple files with a similar
name & file type, eg. *A*.csv.

With my next macro, I open 3 report csv files (*_accept, *_warning &
*_rejected), format & combine them, then split them up into 3 xls workbooks
containing portions of each file. The new workbooks are named A*.xls,
B*.xls & C*.xls. Currently, I open each file individually, then save then
individually, without any problems. However, I wish to update the macro so
that I specify a portion of the file names to open all 3 files, and use that
same string as part of the saved file name. Using the "Acorn Method", I
have written this macro which will return the answer that is given;

Sub Ask_and_Answer()
Dim fAns As String
fAns = InputBox("What number will you choose?")
MsgBox fAns, , "Your Answer is:"
End Sub

How do I use the answer box to open fAns_accept.csv, fAns_warning.csv &
fAns_reject.csv, process them as above, and save them as A_fAns.xls,
B_fAns.xls & C_fAns.xls?

Any help would be greatly appreciated.


Thanks in advance
Andrew


"Tom Ogilvy" wrote in message
...
Sub Macro1()
Dim sName as String
sName = Dir("C:\Data\*.xls")
do while sName < ""
Workbooks.Open Filename:=sName
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy


"ianripping " wrote in message
...
Currently I have a mcro that opens up one workbook: -

Sub Macro1()
Workbooks.Open Filename:="C:\Data\Book2.xls"
End Sub

Can I make this Macro open all .xls files in the current Directory: -
Like

Sub Macro1()
Workbooks.Open Filename:="C:\Data\*.xls"
End Sub

Any ideas?


---
Message posted from http://www.ExcelForum.com/





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
Opening multiple excel workbooks at once Bill Excel Discussion (Misc queries) 0 March 6th 10 01:12 AM
Opening multiple workbooks in Excel bdigs Excel Discussion (Misc queries) 3 February 21st 08 02:35 AM
Opening Multiple Workbooks SJT Excel Discussion (Misc queries) 1 June 6th 06 06:32 PM
Opening multiple workbooks in separate screens CS043 New Users to Excel 3 January 10th 06 02:39 PM
Opening Multiple Workbooks MISMitch Excel Programming 1 August 25th 03 05:29 PM


All times are GMT +1. The time now is 10:22 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"