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#
  4. loop through opened word document c# win app

loop through opened word document c# win app

Scheduled Pinned Locked Moved C#
csharpregex
2 Posts 2 Posters 1 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.
  • F Offline
    F Offline
    fady_sayegh
    wrote on last edited by
    #1

    hi to all, i need to iterate through the documents that are open with winword. for exp : suppose we have 5 documents opened with winword. I need to loop through theese 5 documents to see if one of them match the one i search. And if yes, i want to close it (close the document and not winword) best regards and thanks in advance fady

    G 1 Reply Last reply
    0
    • F fady_sayegh

      hi to all, i need to iterate through the documents that are open with winword. for exp : suppose we have 5 documents opened with winword. I need to loop through theese 5 documents to see if one of them match the one i search. And if yes, i want to close it (close the document and not winword) best regards and thanks in advance fady

      G Offline
      G Offline
      Gokulan Venattil
      wrote on last edited by
      #2

      :)Hi, Hope this piece of code will help you. //Add the Microsoft Word 11.0 Object Library Reference using System.Runtime.InteropServices; using Microsoft.Office.Interop.Word; //Fields private object objSave = false; private object objOrgFormat; private object objRouteDoc; private void IterateWordDocs() { //Get the active Word Application GetWordApplication() //Iterate docs foreach (Microsoft.Office.Interop.Word.Document doc in WordApp.Documents) { if(doc.Name == "YourDocName") doc.Close(ref objSave,ref objOrgFormat,ref objRouteDoc); } } public void GetWordApplication() { Type typeVisioApp = Type.GetTypeFromProgID("Word.Application"); object objWord = Marshal.GetActiveObject("Word.Application"); this.WordApp = (Microsoft.Office.Interop.Word.Application) Marshal.CreateWrapperOfType (objWord, typeVisioApp); } Regards Gokulan -- modified at 2:03 Wednesday 28th December, 2005

      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