open excel file via VBA with a twist

mithu81

Board Regular
Joined
Feb 8, 2007
Messages
138
Hi.
I have to make changes to about 100 xls files on a monthly basis.. These 100 files are in about 30 folders.

within each folder amongst other excel files there are 2 that start with "pre" and "post"
Example:

pre-dd352.xls and post-24356.xls

the text after pre and post are subject to change on a monthly basis. is there anyway i can get excel to open the pre and post files by looking for the words "pre" and use a wild card to get the rest. so basically "pre" wildcard ".xls" is what it should open?

I will be using Workbooks.Open Filename:="C:\dailyword\pre33d5.xls" command to open these books..

Any help would be great
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
That sounds like it could get dangerous. Aren't you looking at the potential of 30+ workbooks opening at the same time? I don't know a computer alive today that could handle that.
 
Upvote 0
nope I will open one.. make the changes i need to make and then close it out.. then open the next.
 
Upvote 0
use a loop with dir to find the filenames
Code:
spath = "C:\dailyword\"
sfile = dir(spath & "pre*.xls)
Workbooks.Open Filename:=spath & sfile
you would need to loop through the folders, within each iteration of the loop, loop through both the pre and post files separately
i don't know how you can loop through the folders as i don't know the folder structure, if they are all subfolders of some main folder you can loop recursively through the main folder and its sub folders
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top