Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting exception in Open Method.

lpDisp = xlBooks.Open(a_sFileName,covOptional,covOptional,
    covOptional,covOptional,covOptional,covOptional,
    covOptional,covOptional,covOptional,covOptional,
    covOptional,covOptional,covOptional,covOptional);


LPDISPATCH Workbooks::Open(LPCTSTR Filename, const VARIANT& UpdateLinks, const VARIANT& ReadOnly, const VARIANT& Format, const VARIANT& Password, const VARIANT& WriteResPassword, const VARIANT& IgnoreReadOnlyRecommended, const VARIANT& Origin, 
		const VARIANT& Delimiter, const VARIANT& Editable, const VARIANT& Notify, const VARIANT& Converter, const VARIANT& AddToMru, const VARIANT& Local, const VARIANT& CorruptLoad)
{
	LPDISPATCH result;
	static BYTE parms[] =
		VTS_BSTR VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT;
	InvokeHelper(0x783, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms,
		Filename, &UpdateLinks, &ReadOnly, &Format, &Password, &WriteResPassword, &IgnoreReadOnlyRecommended, &Origin, &Delimiter, &Editable, &Notify, &Converter, &AddToMru, &Local, &CorruptLoad);
	return result;
}


What I have tried:

It seems
excel interop
issue.
Posted
Updated 31-Mar-20 5:38am
Comments
Richard MacCutchan 31-Mar-20 10:25am    
It could be anything. You need to use your debugger to check all the parameters in the Open call.
Stefan_Lang 31-Mar-20 10:57am    
Ahh, the mighty VARIANT ... it's been ages I last had to use these, and I'm happy these days are past.

You have my condolences.
Greg Utas 31-Mar-20 13:24pm    
I've never used it. I looked at it and closed my browser page while retching.

1 solution

This is the clear sign that you have not properly prepared your open function. My best guess is that these parameters arent so optional, but are mandatory in some scenarios. You must not only initialize a variant with some proper value but also with the type.

bonus tip: open in read-only mode and try a text file
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900