Consulting

Results 1 to 4 of 4

Thread: Solved: open xlsx file with part of name

  1. #1
    VBAX Regular
    Joined
    Apr 2011
    Posts
    43
    Location

    Solved: open xlsx file with part of name

    HI,

    I have this file name: "April 2011 Ref Data" and the first part (April 2011) will be changed every month.

    So I am trying to use a wildcard to open it. This is what I have so far:

    [VBA]Workbooks.Open (ThisWorkbook.Path & "\" & "*" & "Ref Data.xlsx")[/VBA]

    Any ideas why it is not working??

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [vba] Dim xlsx As String
    xlsx = ThisWorkbook.Path & "\" & Format(Date, "mmmm yyyy") & " Ref Data.xlsx"
    Workbooks.Open xlsx[/vba]

  3. #3
    VBAX Regular
    Joined
    Apr 2011
    Posts
    43
    Location
    Quote Originally Posted by Kenneth Hobs
    [vba] Dim xlsx As String
    xlsx = ThisWorkbook.Path & "\" & Format(Date, "mmmm yyyy") & " Ref Data.xlsx"
    Workbooks.Open xlsx[/vba]
    This is searching August, but i need it to search for previous month - July for example, because I don't have data for the current month.

  4. #4
    VBAX Regular
    Joined
    Apr 2011
    Posts
    43
    Location
    Got it!

    [VBA]xlsx = ThisWorkbook.Path & "\" & Format(DateAdd("m", -1, Date), "mmmm yyyy") & " Reference Data.xlsx"[/VBA]

    Thanks a lot, Kenneth!!

Posting Permissions

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