none
MS Word 2007 Automation - Problem with documents saved in '.doc' format.. RRS feed

  • Question

  • In my application I have a functionality to create analysis reports. I basically create HTML report, however, user has the option to generate report in word format (*.docx and *.doc).

    For creating reports in word format I do these simple steps -First create HTML report. Next start new MS Word instance and open the HTML report in to it. Then I do 'Save As' with required format on word document.

    PROBLEM - When I open the saved word file and manually try to do save as, the default 'Save as type' displayed on save as dialog is always shown as 'Word Document' . This happens even though I created a '*.doc' file.

    EXPECTED RESULT - When I create a '*.doc' document and do save as from word the 'Save as type' displayed on save as dialog should be 'Word 97-2003 Document '.

    The code is as below -

    --------------------------------------------------------------------------------------

    _Application                oWord;
    word::Documents        objDocs;
    word::_Document        objNewDoc; 

    COleVariant                 vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR),  vtTrue((short)TRUE), vtFalse((short)FALSE);          

    oWord.CreateDispatch(L"Word.Application")

    _variant_t strFile = "Myfile.html";

    // Get document collection handle.
     objDocs = oWord.GetDocuments();

    // Open the HTML file in Word.
    objNewDoc = objDocs.Open(&strFile, &vtOptional, &vtOptional,                               
                                              &vtOptional, &vtOptional, &vtOptional,
                                              &vtOptional, &vtOptional, &vtOptional,
                                              &vtOptional, &vtOptional,&vtOptional);

     // Make this document as the active one.
     objNewDoc.Activate();

    _variant_t    strNewFilename = "Myfile.doc";

    objNewDoc.SaveAs(&strNewFilename, &vtOptional,  
                                 &vtOptional, &vtOptional, &vtOptional,
                                 &vtOptional, &vtOptional, &vtOptional,
                                 &vtOptional, &vtOptional,&vtOptional);

    // We are done with WORD formatting, so display it to user.        
    oWord.SetVisible(TRUE);
    oWord.SetWindowState(SW_SHOWMAXIMIZED);

    --------------------------------------------------------------------------------------

    Please let me know, how can I solve this problem. I tried setting default save format (oWord.SetDefaultSaveFormat(L"doc")), but that did not helped.

     


    Thanks & Regards, Satyenjit Bagal. SIEMENS Automation and Drives.
    • Moved by Jesse Jiang Monday, December 27, 2010 9:45 AM (From:Visual C++ General)
    Friday, December 24, 2010 12:53 PM

Answers

All replies