Consulting

Results 1 to 5 of 5

Thread: Open latest, partial named file in folder.

  1. #1

    Open latest, partial named file in folder.

    Hi

    I normally use the below code, to find latest published file in folder, and open, which the below works fine.

    Sub OpenLatestFile()
    
    
    
    c00 = "\\\Output\Chris\"
     Workbooks.Open Split(CreateObject("wscript.shell").exec("cmd /c dir """ & c00 & "*"" /b/s/a-d/o-d").stdout.readall, vbCrLf)(0)
     
     
    End Sub

    However, Now, I want to find the latest file within the folder that contains part of the file name.... 'Shopone' for example.

    I have tried various things, such as the below ... which does not work for me.


    Sub OpenLatestFile()
    
    
    
    c00 = "\\\Output\Chris\"
     Workbooks.Open  Split(CreateObject("wscript.shell").exec("cmd /c dir """ & c00  & "*/shopone"" /b/s/a-d/o-d").stdout.readall, vbCrLf)(0)
     
     
    End Sub
    Is anyone able to advise, where I am going wrong?

    Kind regards.

    Chris

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    """ & c00 & "*shopone*""

  3. #3
    thank you so much mana. worked perfectly, missed the closing star.

    thanks again

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Or simply:

    Sub OpenLatestFile()
       c00 = "\\\Output\Chris\*shopone"
       Workbooks.Open  Split(CreateObject("wscript.shell").exec("cmd /c dir """ & c00 & """ /b/s/a-d/o-d").stdout.readall, vbCrLf)(0)
    End Sub

  5. #5
    Thx snb.

    Ill make a note of this also.

Posting Permissions

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