Question : Using wildcards to refer to a filename in a macro

Hello Experts

I was wondering if it was possible to use wildcards when referring to a filename in an excel macro.  What I want to do is to be able to have two excel files open and to be able to switch windows to the other file which will always have filename of type **** MACESS.  As other users will be using the macro I would rather not use the command to simply alternate windows which you could use if there were only the two files open.

Thanks

Answer : Using wildcards to refer to a filename in a macro

If you want to find an open file, you can loop through all workbooks and examine the name. See below. Once you have it, you can either record the full name or keep the object variable to refer to it.

(°v°)
1:
2:
3:
4:
5:
6:
7:
8:
    Dim wkb As Workbook
    For Each wkb In Workbooks
        If wkb.Name Like "*MACESS.xls" Then
            ' found it!
            Debug.Print wkb.Name
            Exit For
        End If
    Next wkb
Random Solutions  
 
programming4us programming4us