Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with opening a document which is allready open in automation?

Problem with opening a document which is allready open in automation?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiondatabasetestingtools
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Banks K
    wrote on last edited by
    #1

    Hello All, I am trying to automate a word document for saving programatically so for that i am trying as follows: first i am loading the document as follows after that i am unable to save document which is modified so how can i do that if anybody have idea about that please share with me. i am giving the code for loading the document it is correctly working also code for saving but it is not saving that document: int CAutoWord::InitAutomation() { // Get the CLSID for Word's Application Object CLSID clsid; CLSIDFromProgID(L"Word.Application", &clsid); // Create an instance of the Word application and obtain the pointer // to the application's IUnknown interface IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**) &pUnk); if (FAILED(hr)) { OutputDebugString("Error in creating Word application instance\n"); Destroy(); return -1; } // Query IUnknown to retrieve a pointer to the IDispatch interface hr = pUnk->QueryInterface(IID_IDispatch, (void**)&m_pDispApp); // Get pointer to Documents interface. DISPPARAMS dp = { NULL, NULL, 0, 0 }; DISPID dispID; LPOLESTR szDoc = L"Documents"; IDispatch* pDocuments = NULL; VARIANT varRetVal; hr = m_pDispApp->GetIDsOfNames(IID_NULL, &szDoc, 1, LOCALE_SYSTEM_DEFAULT, &dispID); hr = m_pDispApp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dp, &varRetVal, NULL, NULL); if (!SUCCEEDED(hr)) { Destroy(); return -1; } // keep the Dispatch pointer in the member variable for later use. m_pDocuments = varRetVal.pdispVal; return 0; } int CAutoWord::SaveDocument() { VARIANT varRetVal; EXCEPINFO excepInfo; VARIANTARG varg; varg.vt = VT_BSTR; varg.bstrVal = _bstr_t("c:\\doc1.doc"); // this is the MS-word document filename, must be changed to a valid filename that exists on disk DISPPARAMS dpSave = { &varg, NULL, 1, 0 }; DISPID dispSaveID; LPOLESTR szSaveDoc = L"Save"; HRESULT hr = m_pDocuments->GetIDsOfNames(IID_NULL, &szSaveDoc, 1, LOCALE_SYSTEM_DEFAULT, &dispSaveID); hr = m_pDocuments->Invoke(dispSaveID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpSave, &varRetVal, &excepInfo, NULL); printf("hello2\n"); if (FAILED(hr)) { OutputDebugString("The document could not be printed\n"); Destroy(); return -1; } }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups