Companion file won't open 'because the file format or file extension is not valid'


Hi @gdgsupport and all,

I’m trying to get the companion files example from the help file to work, so I made a super simple workbook, named it “Test File.xlsx” and saved it in the EXE’s same directory.

Tried to open it with code from the pdf help file (please note that I renamed the file without a space and retried the entire experiment below as well):

wbPath = PathToCompiledFile(“TestFile.xlsx”)

Dim wk As Workbook
Set wk = Workbooks.Open(wbPath, False, False)
MsgBox wk.Sheets(1).Cells(1, 1).Value

but it gives me this error:

The file is not actually corrupt. I know the file exists in the virtual drive exactly as spelled above, because I iterated through the drive. When the file does not exist in the virtual drive, a separate error msg appears about the file not existing, so it’s something about being able to open the file and read it.

Please advise if there’s updated code (or settings) or if this is just an XLSP issue to be resolved.

Thanks for being awesome!



Any ideas why the companion file and vba code aren’t working?


Please disregard. It’s a matter of unchecking this:

if leaving it checked, including proper usage of the setOption helper

NOTE: if you are debugging/stepping through the code and mess up the setOption helpers by not including both of them, it will perpetually not work no matter what corrections you make during that session, because the file is in use in that virtual drive from that point on even though it has not opened fully. You need to exit your app and try again with the proper setOption extensions running correctly the first try.