Consulting

Results 1 to 3 of 3

Thread: Solved: open Excel filename with only certain characters

  1. #1

    Solved: open Excel filename with only certain characters

    Hi Excel VBA experts,

    How do I open an Excel workbook from C:\Data\ that has the first 4 characters as "item"? For example, among all the workbooks and text files in C:\Data\ folder, there is a filename called item-groups-17082009.xls and then in next week this workbook will be replaced with "item-groups-24082009.xls". There is only one file at anytime in this folder with the first 12 characters fixed as "Item-groups-".

    I can't find any related threads and answers. Hope to get some help here.
    Many many thanks.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim fname As String

    fname = Dir("C:\Data\item*.xls", vbNormal)
    If fname <> "" Then

    Workbooks.Open (fname)
    '...
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    You are truly wonderful! Thanks again.

Posting Permissions

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