Excel Macro - Windows Command with Beginning of Filename?

MEUserII

Board Regular
Joined
Oct 27, 2017
Messages
91
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
Platform
  1. Windows
Is there a way to use the Excel Macro command, "Windows", to work with the beginning of a file name? For example, if I want to activate the "window" with the filename "ABCD EFGH IJKL.xlsx" already open it would look like this: Windows("ABCD EFGH IJKL.xlsx").Activate How would I do this for just the first part of the filename, like: "ABCD*.xlsx"?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this;
Code:
Sub Test()

    Dim Strfile As String
    
    Strfile = "ABCD*"
    
    For Each WB In Workbooks
        If WB.Name Like Strfile Then WB.Activate
    Next
    
End Sub
 
Last edited:
Upvote 0
I came up with this answer to my own question: Sub Solution() '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Dim FileOnly1 As String FileOnly1 = ActiveWorkbook.Name Dim RIGHTRESULT1 As String RIGHTRESULT1 = Right((FileOnly1), ((Len(FileOnly1)) - (4))) Windows("ABCD" & RIGHTRESULT1).Activate '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ End Sub
 
Upvote 0
Updated code formatting:

CODE:
Code:
I came up with this answer to my own question:
Sub Solution()
Dim FileOnly1 As String
FileOnly1 = ActiveWorkbook.Name
Dim RIGHTRESULT1 As String
RIGHTRESULT1 = Right((FileOnly1),  ((Len(FileOnly1)) - (4)))

Windows("ABCD" &  RIGHTRESULT1).Activate
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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