简体   繁体   中英

Workbook won't open with VBA

I have a workbook named "Certified Schedule - E&P - Krause & Hall.xlsx" sat in a folder called "Krause & Hall" on our server.

I have a piece of code that looks up the folder and file name based on the vendor, it works for all other vendors but seems to fail with this one. Strangely the file works absolutely fine when manually opened.

I have created a simplified version of the code to test it:

Sub Test() 
Dim Subject As Workbook
Dim Vendor As String

Vendor = "Krause & Hall"
Set Subject = Workbooks.Open("\\amres.ameygroup.net\shareddata\ConsRail\IDH2\LFRRS001\WCRData\SystemsDivision\CP5 Programme E&P Framework\4.0 Commercial\4.1 Subcontract Applications, Certificates and Invoices\Contingent Labour Frameworks\" & Vendor & "\Certified Schedule - E&P - " & Vendor & ".xlsx")

End Sub

This works fine when Vendor = Vital, but not as above.

I get the "run-time error '1004' method 'open' of object 'workbooks' failed" error code

It was because the Krause & Hall file path was 260+ characters, but the Vital path was not. Thanks @Rory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM