Opening All Excel Books In directory

Atecuser1

New Member
Joined
Aug 17, 2006
Messages
35
How do i Moidy this

Code:
Filename = Dir("C:\Documents and Settings\cotem\Desktop\" & "" & "*.xls", 0) 'looks only at Excel files
    While Filename <> ""
        If Left(Filename, 20) = "ATEC Acc Report - " Then
            Workbooks.Open ("C:\Documents and Settings\cotem\Desktop\" & Filename), False
            GoTo Part1
        End If
    Wend

To open all excel files in directory with the starting name of ATEC Acc Report?

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,

assuming you picked this code from some thread, where somebody told it was working, but after you made some modifications it isn't working for you ...

your code is asking to find 20 characters in a string while there are only 18 specified - as far as I can see

Code:
If Left(Filename, 18) = "ATEC Acc Report - " Then
it would be safer to compare "lower case" for both strings, in case someone has written "Atec Acc Report - " or "ATEC ACC REPORT - " or some other combination ...
Code:
If LCase(Left(Filename, 18)) = Lcase("ATEC Acc Report - ") Then
getting further with this ?

kind regards,
Erik

EDIT: you have "GoTo Part1": (avoid GOTO !) what is this doing ? it will exit the loop at once
 
Upvote 0

Forum statistics

Threads
1,214,379
Messages
6,119,190
Members
448,874
Latest member
Lancelots

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