[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Automation with Excel in VC++ - Range::Replace works in 97 but not XP

Posted on 2005-04-10
Medium Priority
Last Modified: 2008-01-09
I've used Automation to format an Excel worksheet, using the Excel 8 type libray so I can target Office versions 97 and later (or so I thought).  I've used the Range::Replace method and when running on a system with Office XP we get the ole error 8002000e Invalid number of parameters, because the XP version of the Replace function takes 8 parameters, whereas the 97 version takes 10.

Quoting from http://support.microsoft.com/kb/244167/EN-US/:

"Office applications that are tested and compiled with earlier versions of a type library continue to work, unchanged, when end users of your product upgrade their Office installations to a more recent version. In this way Office provides backward compatibility." Apparently not.

Early or late binding is no help here - they've broken the interface. As far as I can see I'll have to pick one version of Office to support - or am I missing something?

Any help is appreciated.
Question by:BobJK
  • 3
  • 2

Expert Comment

ID: 13751260
You can use IDispatch interface to know about the function and then invoke accordingly.


Author Comment

ID: 13757989
Excuse my ignorance - the function always has the same DispID - how would I "know" about the function through IDispatch?

Also, assuming this is possible, wouldn't I have to do it for every method I want to invoke, for all current and future versions of Excel? Sounds impossible to maintain.


Accepted Solution

novitiate earned 750 total points
ID: 13758789



you don't need use pDisp->invoke for method call, use above to get the information and do as you do it normally.

yeah it would be difficult to maintaing all version, you might want to write adapters for known versions, rest ~_~

as of now this is what is coming to mind, will let you know if there are any other better solutions.


Author Comment

ID: 13759503
Thanks for the quick response _novi_, that gets me out of the immediate trouble.

Author Comment

ID: 13787596
Sorry, I may have been a bit premature in accepting the answer. _novi_, are you referring to the dispatch interface for the Excel.Application object? If so, this does not expose the methods for the IRange interface. I tried calling QueryInterface on IUnknown to get the IRange interface without luck, ie

// The guid for the Range dispatch interface
CLSID IID_Range  = {0x00020846, 0x0, 0x0, {0xC0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46}};
pUnk->QueryInterface(IID_Range, (void**) &pDisp)

I also tried calling it on the IDispatch interface, still no luck. The guid is definitely correct, I got it from browsing the type library in the ole viewer. Am I missing something obvious? Thanks in advance - if I need to submit this as a separate question I will.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question