Get Workbook Name From Available Open Workbooks

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,566
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Can someone help me find an Excel VBA solution to step through my open workbooks to find the one with a name (always) formatted as "mmm-dd (ddd) Data.xlsx", and return the name of that file?

I have 3 open workbooks and I need to find the file name of the one, for example, named "Jun-24 (Mon) Data.xlsx"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Code:
Sub t()
Dim wb As Workbook, nm As String
    For Each wb In Application.Workbooks
        If wb.Name = "Jun-24 (Mon) Data.xlsx" Then
            nm = wb.FullName
            MsgBox nm
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Thanks JLGWhiz! Maybe I did a poor job of explaining my needs.

I am looking to find the name of the workbook thats open that has that format. This workbook is dynamic and will always have a different name. Only one workbook will ever be open that has a name with the format "mmm-dd (ddd) data.xlsx" and its the one I need the filename of.

In your solution, the name of the file is known which won't be the case.
 
Last edited:
Upvote 0
Try looking for it with
Code:
If wb.Name Like "*Data.xlsx" Then
    MsgBox wb.Name
End If

Otherwise, you might have to use regex.
 
Last edited:
Upvote 0
Thank you. That was what I was uncertain about ... how to find it.
 
Upvote 0

Forum statistics

Threads
1,223,715
Messages
6,174,065
Members
452,542
Latest member
Bricklin

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