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
  1. Home
  2. General Programming
  3. COM
  4. Closing document in Word under Automation

Closing document in Word under Automation

Scheduled Pinned Locked Moved COM
csharpc++htmldatabasecom
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.
  • D Offline
    D Offline
    Dave Loeser
    wrote on last edited by
    #1

    I'm using Word Automation (using C++ here) as an out of proc exe to Find and Replace text within documents. When I create an instance of Word I would prefer to keep that instance open and then open, search/replace, close and repeat until I am finished with all documents and then quit the word application instance. I have this working but I have an odd (or maybe it is a common) problem. When I close the document, Word becomes visible. Here's how I am closeing the document.

    void CMSWord9Automation::CloseDoc()
    {
    	try
    	{
    		if(m_pOpenDoc) // Word::_DocumentPtr
    		{
    			//m_pWord->Visible = VARIANT_FALSE; // Does not work
    			m_pWord->Documents->Close(
    				&_variant_t(Word::wdDoNotSaveChanges),
    				&_variant_t(vtMissing),
    				&_variant_t(VARIANT_FALSE));
    
    			//m_pWord->Visible = VARIANT_FALSE; // This resets word to invisible but isn't really the desired approach
    			m_pOpenDoc.Release();
    		}
    	}
    	catch(_com_error& ComError) 
    	{
    		DumpComError(ComError);
    	}
    }
    

    I'm looking for any information on how to stop Word from displaying when I close the opened document. Thanks, Dave Dak Lozar Loeser When access is allowed to a member, it said to be accessible. Otherwise, it is inaccessible. - MSDN:C# Programmer's Reference

    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