VBA Activate open workbook with name ending as current date

Warages

New Member
Joined
Feb 10, 2018
Messages
2
Hi,

I have multiple files ending with current date, but the start of the filename is always different.
For example "sun_(current date)" and "moon_(current date)" etc. The start of the file names are not known.

I will have the macro file open and one of the multiple files that have different names (but same ending).
I try to activate the window of the workbook that ends with the current date, so that the tabs are inserted over to the macro file.
Only the file with the macro and one other file will be open at the same time.

I could only make it work if the start of the filename is always the same with a different ending.
I can't make it work if the start is different.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Are the dates always in the same format?

What is the code you have now that can open the file based on the beginning portion of its name?
 
Upvote 0
The dates are always in the same format.
I can activate the file "100218_moon" with the code below.
I wish to activate the file with the name "moon_100218" instead.
The name 'moon' is just an example and could be anything.

Sub ActivateFile()
Dim wb As Workbook
For Each wb In Application.Workbooks
If wb.Name Like Format(Date, "ddmmyy") & "_*" Then
wb.Activate
Exit Sub
End If
Next wb
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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