Reputation: 167
I'm attempting to open a workbook, but Excel gives me an error message saying that it cannot find the workbook.
Dim pricing As Workbook
dim fname As String
fname = Dir(ActiveWorkbook.Path & "\Budget Pricing Detail*.csv")
Set pricing = Workbooks.Open(Filename:=fname, UpdateLinks:=False)
As you can see I'm using a wildcard to pull the file name as the last bit of the filename will be different for each instance. What's weird to me as that when Excel gives me the error box it actually names the WHOLE file (even though I never did in my code) I want it to find and says it can't find it. Also what's weird is that this was working already and all of a sudden now it isn't.
Upvotes: 0
Views: 1706
Reputation: 600
I think DIR only returns the filename, and not the entire path. Try:
fname = ActiveWorkbook.Path & "\" & Dir(ActiveWorkbook.Path & "\Budget Pricing Detail*.csv")
Upvotes: 1