Get Workbook Name From Available Open Workbooks

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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