• Passing SafeArray in Word Automating ? (2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Passing SafeArray in Word Automating ? (2000)

    Author
    Topic
    #385874

    In a MS Word automating program, I want to get a ShapeRange from a Shapes object, which need a SafeArray parameter. I wrote the following code:
    ——————————————
    COleSafeArray sa;
    DWORD bounds=1;
    sa.Create(VT_VARIANT,1,&bounds);
    COleVariant v_ind((long)1,VT_I4);
    long ind=0;
    sa.PutElement(&ind,&v_ind);
    //sa.Detach();

    CShapes shapes(doc.GetShapes());
    CShapeRange sr(shapes.Range(sa));
    ——————————————-
    It just throws an exception saying that the parameter has an invalid value. If I Detach the array before passing it to the Range method, the array becomes empty. Another exception is thrown out saying that out of bound.

    Anyone can tell me how can I get it right?
    Thx

    Viewing 1 reply thread
    Author
    Replies
    • #667344

      Tough one to answer, not knowing C.

      It looks like you’ve built custom methods like GetShapes to get a shapes collection; don’t know if that is complicating things, but if it’s any help, in VBA, “Shapes.Range(index)” wants an Integer or Long for index; it doesn’t look like it will handle an array.

      Gary

    • #667346

      Couple thoughts:

      (1) Are you sure there is a GetShapes method available? To return the Shapes collection in Word you typically use something like:

      Document.Shapes

      (2) What does the data in your array look like?

      I assume the 1 element is for testing, but if you only have one element, you can use either a string or integer parameter, as the case may be, and skip the array entirely.

      If you really do have an array, and you need to return multiple shapes as a single ShapeRange, maybe there’s another way.

      • #667354

        One element just for testing. In the program I need get several shapes with arbitary names or index.
        I don’t know other ways to do it.
        What’s even strange is that the code works perfectly for PowerPoint, but for Word, I always get the exception.

    Viewing 1 reply thread
    Reply To: Passing SafeArray in Word Automating ? (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: