473,850 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word COM integration

I am noticing a problem when interfacing with Word through my C# code.
What I am trying to do is enumerate through the documents currently
open in Word. I have noticed issues with this on both methods I can
think to try.

We are using COM objects, because we need compatibility with Word 2000.
I am testing this against Word 2003 however.

For simplicity sake, I have two documents open, 1.doc and 2.doc.

Method 1:
If I do
foreach(Word.Do cument doc in wordHandle.Docu ments) {}
then the first time this is run, I get the correct documents. If I try
to enumerate through a second time, it only runs through once, even
though wordHandle.Docu ments.Count is 2.

This doesn't work, so let's try with for...

Method 2:
If I do
for(int i=1; i < wordHandle.Docu ments.Count+1; i++)
Object oI = i;
Word.Document doc = wordHandle.Docu ments.Item(ref oI);
then the first time this is run, I get 2 documents, but it is the same
two documents. I get 1.doc and 1.doc, both times. After the first
run, I get the correct two documents, 1.doc and 2.doc.

So, it seems that to get the correct documents every time, I would want
to do the foreach the first time, then use for each time after. This
seems like a serious pain, especially since I don't know what will
happen if a third document is opened after we already enumerated

Has anyone run into this issue and found a good solution?


Nov 16 '05 #1
0 1473

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: David Thielen | last post by:
When we sat down to design a new generation of J2EE-based reporting tools, we naturally assumed that somewhere along the line we’d have to make compromises to satisfy both the technical staff and the report users... It turns out compromise wasn’t necessary. Windward Reports is here, and both users and IT types are telling us that it delivers all their top Wish List items, and then some. That pleases us, although in all humility, we must...
by: insureallrisk | last post by:
If we want to integrate word in dot net, we need to add the com library reference in the project. Do you know how I copy the dll onto my dot net framework without using the add reference because I am not using the visual studio. Is there any link that you know where I can get some hints? Thanks. Ray
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies (http://www.datadirect.com), the software industry leader in standards-based components for connecting applications to data and an operating unit of Progress Software Corporation, today announced the release of DataDirect XQuery(TM), the first embeddable...
by: scorpion53061 | last post by:
My boss is more and more asking me to get into areas of report formatting and such with the primarily database apps that I write. I am not pleased with Crystal and some of the pitfalls I have seen with this particualar report tool. I would like to delve into Word automation ( I believe you can control page breaks and such with this). Can someone point me to a good how to with the various methods available there?
by: Mason | last post by:
What I'd like to do is design a small VB.Net (2003) application that populates various labels in a word document (Office 2000), as well as selects what other word documents the user would like concatenated to the end of the main word document. Basically, I'd have a template word document that VB copies, then opens. After opening it, VB would then use values that the user had selected via the VB Form to populate several labels. Then,...
by: Jesse Johnson | last post by:
I have kind of a complicated issue. I need to be able to have someone come to our online application and simply hit "Create Labels" from there idealy Microsoft Word would pop up and all of our records from the SQL Server would be inserted into a special Avery template. I dont know where to start. could anybody point me into the right direction? Any help would be wonderful. Thanks in advance. -- Jesse Johnson
by: Bill Partridge | last post by:
Hi, I have a VB.NET application that is integrating with Microsoft Word to open up a Word document. How can I open up the Word document in Read/Write mode, the default opens it up in Read OPnly Mode. Here is the line of code that i am using. appWord.Documents.Open(pServiceLoad) pServiceLoad is a variable containg the path and file name.
by: Antoine De Groote | last post by:
Hi there, I have a word document containing pictures and text. This documents holds several 'ABCDEF' strings which serve as a placeholder for names. Now I want to replace these occurences with names in a list (members). I open both input and output file in binary mode and do the transformation. However, I can't open the resulting file, Word just telling that there was an error. Does anybody what I am doing wrong? Oh, and is this...
by: Derek Hart | last post by:
I am using late bound Microsoft Word integration with a vb.net winforms application. If I run code such as the following: Dim objWord As Object Dim objWrdDoc As Object Dim count As Integer Dim filename As String filename = "c:\temp\mergedata\1.doc" objWord = CreateObject("Word.Application") For count = 1 To 10000
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.