Consulting

Results 1 to 5 of 5

Thread: File name with some changing numbers

  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    40
    Location

    File name with some changing numbers

    Hi everyone,

    I have a file named like : 20160105_1010_StockDetails_Raws

    20160105 : no problem = Today's date

    But I have the 1010 which is a complete random number.

    Is there any way to deal with it? does **** exist in VBA?


    Thank you very much in advance.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Is there any way to deal with it? does **** exist in VBA?
    Yes and Sort Of

    Option Explicit
    Sub test()
        Dim sPath As String, sFind As String, sFound As String, sNotFound As String
        
        sPath = "c:\Users\Daddy\Documents\"
        
        sFind = sPath & Format(Date, "yyyymmdd") & "_****_" & "StockDetails_Raws.txt"
        sFound = Dir(sFind)
        MsgBox sFound                            ' pass string to FileOpen
    
        sFind = sPath & Format(Date, "yyyymmdd") & "_****_" & "XStockDetails_Raws.txt"
        sNotFound = Dir(sFind)  ' empty string
        MsgBox sNotFound
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Dec 2015
    Posts
    40
    Location
    Thank you very much Paul.
    I will try that and let you know.
    Many thanks !

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Only need one *.
    Can use 4 "?"
    sFind = sPath & Format(Date, "yyyymmdd") & "_*_" & "StockDetails_Raws.txt"
    sFind = sPath & Format(Date, "yyyymmdd") & "_????_" & "StockDetails_Raws.txt"
    "_*_" will match "_12345_" and "_123_"

    "_????_" will not match "_12345_" nor "_123_"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    @SamT -- must be too much New Years

    @ced0802-- while the **** would still work, SamT's suggestions are more elegant
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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