Word Automation-SaveAs Parameters Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyankalakhe
    New Member
    • Jun 2007
    • 5

    Word Automation-SaveAs Parameters Error

    Hi,
    I'm new to Automation and am currently trying a code from msdn




    to automate a word application(Off ice 2003) in VC++ using MFC. However,I keep getting an errror saying that the SaveAs parameter cannot take 11 parameters.

    Can anyone help me?

    priyanka
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What does your call look like?

    Comment

    • priyankalakhe
      New Member
      • Jun 2007
      • 5

      #3
      Originally posted by weaknessforcats
      What does your call look like?
      Hi..
      Here is the function call..

      oActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
      COleVariant((sh ort)0),
      vFalse, COleVariant("") , vTrue, COleVariant("") ,
      vFalse, vFalse, vFalse, vFalse,vFalse);

      Its for word 2003 like i mentioned earlier.. Any idea how many params it takes??

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by priyankalakhe
        oActiveDoc.Save As(COleVariant( "e:\\priyanka\\ testdoc2.doc"),
        What is the function prototype of oActiveDoc.Save As()???

        The only SaveAS I found was one in C# that takes 16 arguments.

        Comment

        • priyankalakhe
          New Member
          • Jun 2007
          • 5

          #5
          Hi,
          I'll try to find out more about the oActiveDoc.Save As method prototype. Meanwhile i started trying my hand on excel automation and i'm trying to insert data into the excel sheet. For data that is static i don't have a problem but for data that i want to insert at run time,the function that i lifted off msdn does not quite work.
          I'm trying to insert strings and numbers of type double at runtime from a source. The function looks like :

          void FillSafeArrayOf String(OLECHAR FAR* sz,int iRow,int iCol,COleSafeAr ray* sa)
          {

          VARIANT v;
          long index[2];

          index[0] = iRow;
          index[1] = iCol;

          VariantInit(&v) ; //DOUBLE dblVal; // VT_R8.
          v.vt = VT_BSTR; //BSTR bstrVal; // VT_BSTR.
          v.bstrVal = SysAllocString( sz);
          sa->PutElement(ind ex, v.bstrVal);
          SysFreeString(v .bstrVal);
          VariantClear(&v );

          }

          void FillSafeArrayOf Double(double dval,int iRow,int iCol,COleSafeAr ray* sa)
          {

          VARIANT v;
          long index[2];

          index[0] = iRow;
          index[1] = iCol;

          VariantInit(&v) ; //DOUBLE dblVal; // VT_R8.
          v.vt = VT_R8; //BSTR bstrVal; // VT_BSTR.
          v.dblVal =dval;
          sa->PutElement(ind ex,&v);
          VariantClear(&v );

          }

          The first function fills a string and the second a double in the specified cell. The function call looks like :

          COleSafeArray saRet;
          DWORD numElements[]={2,1}; //dimensions
          saRet.Create(VT _BSTR, 2, numElements);

          FillSafeArrayOf String(L"", 0, 0,&saRet); // in the "" would be the string i // want to place at runtime. I can't get rid of the 'L' and dyanamically placing it.
          FillSafeArrayOf String(L"", 1, 0,&saRet);

          range = sheet.GetRange( COleVariant("C2 "), COleVariant("C3 "));
          range.SetValue2 (COleVariant(sa Ret));

          saRet.Detach();

          Similarly for numbers : i want to insert the value dval1 into the cell F10.
          COleSafeArray saRet;
          double dval1;
          dval1=m_dNumber OfRotatableBond s;
          dval1=23.23;

          DWORD numElements[]={1,1}; //dimensions
          saRet.Create(VT _R8, 2, numElements);

          FillSafeArrayOf Double(dval1,0, 0,&saRet);

          range = sheet.GetRange( COleVariant("F1 0"), COleVariant("F1 0"));
          range.SetValue2 (COleVariant(sa Ret));

          saRet.Detach();


          This is not working. Could anyone please point out where i'm going wrong? Or else give me a reference to some code or another way of doing it?

          Thanks a lot in advance for the efforts..
          Priyanka

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            This code:
            Originally posted by priyankalakhe
            v.bstrVal = SysAllocString( sz);
            sa->PutElement(ind ex, v.bstrVal);
            SysFreeString(v .bstrVal);
            looks fishy.

            First, you allocate a BSTR
            Second, you call PutElement with the BSTR.
            Third, you delete the BSTR.

            I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.

            I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.

            I recommend using a smart pointer here. Check this article on Handle Classes.

            Comment

            • priyankalakhe
              New Member
              • Jun 2007
              • 5

              #7
              Originally posted by weaknessforcats
              This code:


              looks fishy.

              First, you allocate a BSTR
              Second, you call PutElement with the BSTR.
              Third, you delete the BSTR.

              I believe that you have just deleted the BSTR you allocated. PutElement() just passes the BTSR along as a pointer.

              I do not believe you can delete this BSTR until there are no copies of the pointer to that BSTR left in your program.

              I recommend using a smart pointer here. Check this article on Handle Classes.

              Thanks.. I got rid of those two functions and tried a simpler one using Setvalue2(). It worked!

              Comment

              • gnanapoongothai
                New Member
                • Jun 2007
                • 62

                #8
                Originally posted by priyankalakhe
                Hi,
                I'm new to Automation and am currently trying a code from msdn




                to automate a word application(Off ice 2003) in VC++ using MFC. However,I keep getting an errror saying that the SaveAs parameter cannot take 11 parameters.

                Can anyone help me?

                priyanka


                HI,
                u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.

                Comment

                • priyankalakhe
                  New Member
                  • Jun 2007
                  • 5

                  #9
                  Originally posted by gnanapoongothai
                  HI,
                  u were specifying abt automation. I have get data and write to a file say excel, in real time will this automation wil be useful. i am using TCp/IP socket for client server connection. Plz do reply.
                  Hi,
                  I really have no idea.. U should try asking around someone else in the forum.I'm a newbie too.
                  Priyanka

                  Comment

                  Working...