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
 

Some videos you may like

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

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Watch MrExcel Video

Forum statistics

Threads
1,113,952
Messages
5,545,143
Members
410,666
Latest member
Al3cs
Top