VBA TO Open certain files by date

drew101

New Member
Joined
Jun 14, 2017
Messages
12
I am trying to write a vba myself and need some help. I have searched the web and have stared with my first steps of Opening the Files that I have in my folder.See the code below. Next I need help, within this code to have it open only certain files that contain the date. For example with the examples below I only want to open the files with 5-17-2017. When running this macro the date selection that I wish to open my change.

test05-17-2017.xls
newtes05-17-2017.xls
oldtest05-15-2017.xls






Code:
Sub OpenFilesToday()
 Dim MyFolder As String
 Dim MyFile As String
 MyFolder = "C:\Users\drew\Documents"
 MyFile = Dir(MyFolder & "\*.xls*")
 Do While MyFile <> ""
 Workbooks.Open Filename:=MyFolder & "\" & MyFile
 MyFile = Dir
 Loop
 End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
modify to
Code:
MyFile = Dir(MyFolder & "\[COLOR=#B22222]*5-17-2017[/COLOR][COLOR=#000080]*.[/COLOR]xls*")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,025
Members
449,060
Latest member
LinusJE

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