Opening files that contains "Word" in String

ktkelly_1

New Member
Joined
Jun 13, 2019
Messages
17
Hello I am extracting data from files that change names every day. I was hoping to find some kind of macro code that could extract, rather, a file that contained a general name in the string that is in a specific folder/path. For example

S:\Projects\STV_Plus\2.2.2.6 KPI\CC CINCO KPI YYmmdd

here we have a file that changes dates every so often (not at a consistent level that is) I want to be able to say

path = S:\Projects\STV_Plus\2.2.2.6 KPI\
find and open the file that contains the words "CC CINCO KPI" within the string

I was also hoping to find out how to activate the window when needed

for example:

Windows(Filename). Activate

where Filename =
path = S:\Projects\STV_Plus\2.2.2.6 KPI\
find and open the file that contains the words "CC CINCO KPI" within the string
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello ktkelly_1,

What extension do these files have? This will determine the code needed to open them and activate the window.
 
Upvote 0
How about
Code:
Sub ktkelly_1()
   Dim Pth As String, Srch As String, Fname As String
   Dim Wbk As Workbook
   
   Pth = "S:\Projects\STV_Plus\2.2.2.6 KPI\"
   Srch = "*CC CINCO KPI*"
   Fname = Dir(Pth & Srch & ".xlsx")
   Do While Fname <> ""
      Set Wbk = Workbooks.Open(Pth & Fname)
      'do something here
      Wbk.Close False
      Fname = Dir
   Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,570
Latest member
rik81h

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