Excel Macro Activate another open book based on partial name

NormChart55

New Member
Joined
Feb 22, 2022
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am wanting to use a macro to check data from another open workbook. The problem is that the workbook name will always change and have a new date. It will always start with 'Import' but daily would adjust (example: 'Import 10.23.23'). How can I adjust this to only look for 'Import" and exclude the date so that each day's file can be used? Below is example currently, but we have to manually save the file to remove the date. Thanks for any help on this.


Excel Formula:
Windows("Import.xlsx").Activate

Range("A1:AB1").Select

With Selection
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Place this macro in your first workbook and make sure that both workbooks are the only open workbooks. The variable 'WB2' will give you the name of the other workbook.
VBA Code:
Sub test()
    Dim WB As Workbook, wbName As String
    For Each WB In Workbooks
        If WB.Name <> ThisWorkbook.Name Then
            WB2 = WB.Name
        End If
    Next WB
End Sub
 
Upvote 0
Thank you for that solution. We tend to have a lot of files open during this process so closing and reopening would really add the same time back when are trying to save during this. Is there a way to possibly include the date in the windows activate portion and have that change based on the current date?


Excel Formula:
 Windows("Import & TODAYS DATE FORMATTED 10.23.23.xlsx").Activate

Range("A1:AB1").Select

With Selection
 
Upvote 0
Is this what you are looking for?
VBA Code:
Windows("Import" & Format(Date, "mm.dd.yy") & ".xlsx").Activate
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,805
Members
449,262
Latest member
hideto94

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