Search code examples
comc++builderole

OleProcedure() C++ Builder 10.3


I try to select 10 characters in Word document with C++ Builder.

VBA method looks as follows:

Selection.SetRange Start:=0, End:=10

How to correctly pass parameters to C++ Builder method?

I tried several options, but did not succeed.

selection.OleProcedure("SetRange", Start:=0, End:=10)
selection.OleProcedure("SetRange", "Start:=0", "End:=10")
selection.OleProcedure("SetRange", 0, 10)

Solution

  • OleProcedure() does not support named parameters 1. You have to pass the parameter values in the same order that they are declared by the COM object, which in this case is:

    expression.SetRange(Start, End)
    

    So selection.OleProcedure("SetRange", 0, 10) should work just fine. If it is not, you need to be more specific about what exactly is not working for you.

    1: if you want to use named parameters, you will have to access the variant's held IDispatch interface and call its IDispatch::Invoke() method directly, providing it with a DISPPARAMS struct containing the desired names and values.