Results 1 to 4 of 4

Thread: Opening files that contains "Word" in String
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Opening files that contains "Word" in String

    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

  2. #2
    Board Regular Leith Ross's Avatar
    Join Date
    Mar 2008
    Location
    San Francisco, CA
    Posts
    1,823
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Opening files that contains "Word" in String

    Hello ktkelly_1,

    What extension do these files have? This will determine the code needed to open them and activate the window.
    Sincerely,
    Leith Ross

  3. #3
    New Member
    Join Date
    Jun 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Opening files that contains "Word" in String

    these are all .xlsx files.

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,228
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Opening files that contains "Word" in String

    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
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •