Macro to check if file name with asterisk is open

Sahak

Well-known Member
Joined
Nov 10, 2006
Messages
1,012
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Hi all,

My file names start with ABC & some numbers in parentheses: ABC (4877).xls or ABC (9218).xls or ABC (2234).xls est.
From other file I would like to know if any file which name starts with ABC is open
Something like this: ABC*.xls (using asterisk)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
try
Code:
[/FONT]
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Sub chck()
Dim wb As Workbook
For Each wb In Workbooks
If wb.Name Like "ABC*.*" Then MsgBox "Open"[/FONT]
[FONT=Courier New]Next wb
End Sub[/FONT]
[FONT=Courier New]
 
Upvote 0
Does anyone know how to check if a workbook is open based on the value entered into a InputBox?
Like if "Personal.xls" is entered into an InputBox (without quotations) how do I check if that workbook is open at the moment?
 
Upvote 0
Just enter the book name and not the entention [like .xls]
Code:
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Sub chck()[/FONT]
[FONT=Courier New]Dim x As String[/FONT]
[FONT=Courier New]Dim wb As Workbook[/FONT]
[FONT=Courier New]x = InputBox("Please enter the name of the Workbook", "Provide info", "")[/FONT]
[FONT=Courier New]For Each wb In Workbooks[/FONT]
[FONT=Courier New]If wb.Name Like x & "*.*" Then MsgBox "Open"[/FONT]
[FONT=Courier New]Next wb[/FONT]
[FONT=Courier New]End Sub[/FONT]
 
Upvote 0
Only problem is...I need it to check when multiple workbooks are open and I need code to run as result of the answer, that is; If it isn't open exit the sub, If it is open continue with the sub.
However if the first workbook is not the one I'm after but the one I am is open, it will exit the sub after the first result.
 
Upvote 0
No need to poll the workbooks:

Code:
Sub CheckIfOpen()
Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks(InputBox("Please enter the name of the Workbook", "Provide info", ""))
If wb Is Nothing Then
    'Put your code here for when the book is closed
else
    'put your code here for when it is open
end if
End Sub

Even then, it only tests the name of a book, it doesn't actually look to see if a particule book of that name is open. If you have three books with the same name in directories called 1, 2 and 3 on C drive respectively, this will tell you A book is open with that name, it will not tell you if it is the one in a particular DIR that you want.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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