AP1
AP1

Reputation: 167

VBA Error on opening workbook - Cannot find workbook that is there

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.

enter image description here

Upvotes: 0

Views: 1706

Answers (1)

4ndy
4ndy

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

Related Questions