Log in

View Full Version : Solved: open xlsx file with part of name



dani9
08-12-2011, 01:49 AM
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:

Workbooks.Open (ThisWorkbook.Path & "\" & "*" & "Ref Data.xlsx")

Any ideas why it is not working??

Kenneth Hobs
08-12-2011, 02:26 AM
Dim xlsx As String
xlsx = ThisWorkbook.Path & "\" & Format(Date, "mmmm yyyy") & " Ref Data.xlsx"
Workbooks.Open xlsx

dani9
08-12-2011, 03:22 AM
Dim xlsx As String
xlsx = ThisWorkbook.Path & "\" & Format(Date, "mmmm yyyy") & " Ref Data.xlsx"
Workbooks.Open xlsx

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.

dani9
08-12-2011, 03:27 AM
Got it!

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

Thanks a lot, Kenneth!!