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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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




1 Answer
1



I think DIR only returns the filename, and not the entire path. Try:



fname = ActiveWorkbook.Path & "" & Dir(ActiveWorkbook.Path & "Budget Pricing Detail*.csv")


fname = ActiveWorkbook.Path & "" & Dir(ActiveWorkbook.Path & "Budget Pricing Detail*.csv")





That didn't work
– AP1
19 mins ago





@AP1 Sorry, had an extra slash. I have tried it here, and it works for me, now.
– ToshiBoy
15 mins ago





I tried that as well, but no luck
– AP1
11 mins ago





@AP1 If you debug it, can you see what value your fname holds?
– ToshiBoy
3 mins ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived