473,606 Members | 3,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help needed on Word._Document. Words property

31 New Member
Hi,
I am using Office XP PIA's to read a word document. I am able to read the whole content. The problem is that i want to get a particular word in the document instead of the whole content.
Will the _Document.Words property is useful to retrieve word by word form the document??? If it is possible, How to use it???

thanks
Nelluru
Apr 5 '07 #1
12 6541
SammyB
807 Recognized Expert Contributor
Hi,
I am using Office XP PIA's to read a word document. I am able to read the whole content. The problem is that i want to get a particular word in the document instead of the whole content.
Will the _Document.Words property is useful to retrieve word by word form the document??? If it is possible, How to use it???

thanks
Nelluru
It's hard to do Word automation in .NET, but, yes, you can use he Words collection. This example shows word 6 in the doc:
Expand|Select|Wrap|Line Numbers
  1. const string DOC = @"C:\Documents and Settings\Sam\My Documents\Visual Studio 2005\Projects\WordAutomation\Demo.doc";
  2. object ms = System.Reflection.Missing.Value;
  3. Word._Application wdApp = new Word.Application();
  4. wdApp.Visible = true;
  5. object oDoc = (object)DOC;
  6. Word._Document wdDoc = wdApp.Documents.Open(ref oDoc, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms);
  7. Word.Words w = wdDoc.Words;
  8. Word.Range r = w.Item(6);
  9. MessageBox.Show(r.Text);
  10.  
You can see how to use other Word objects in .NET at http://support.microsoft.com/kb/316384
Apr 5 '07 #2
Nelluru
31 New Member
hi,
Please help me..
I am getting this error:
'Microsoft.Offi ce.Interop.Word .Words' does not contain a definition for 'Item'.

Code is:

Microsoft.Offic e.Interop.Word. Words w = wdDoc.Words;
Microsoft.Offic e.Interop.Word. Range r = w.Item(2);


I have included Microsoft.Offic e.Interop.Word dll in my project. And I am using Microsoft Visual C# 2005 Express Edition.

What would be the reason??
Is there anything I am missing???

thanks in Advance
Nelluru
Apr 9 '07 #3
SammyB
807 Recognized Expert Contributor
Hi,
I am using Office XP PIA's to read a word document. I am able to read the whole content. The problem is that i want to get a particular word in the document instead of the whole content.
Will the _Document.Words property is useful to retrieve word by word form the document??? If it is possible, How to use it???

thanks
Nelluru
Just a word of caution. If you are used to working with Word macros, then you will have a tendency to put Word objects together like wdDoc.Words.Ite m(6) instead of dealing with each object separately. This will not always work with C#. VBA kept a lot of details from us & pushed stuff into Variants. C# will not do this, but if you single step through your code, you can usually see what intermediate objects you need to create. I haven't done this with Word, but I have done it with Excel and it was very painful
Apr 10 '07 #4
Nelluru
31 New Member
Just a word of caution. If you are used to working with Word macros, then you will have a tendency to put Word objects together like wdDoc.Words.Ite m(6) instead of dealing with each object separately. This will not always work with C#. VBA kept a lot of details from us & pushed stuff into Variants. C# will not do this, but if you single step through your code, you can usually see what intermediate objects you need to create. I haven't done this with Word, but I have done it with Excel and it was very painful
Hi Sam,
I have already posted the message in the Forum http://www.thescripts.com/forum/thread629828.html . As I did not get any reply, I sent u a private message. And I am also sorry for the late reply. I didn't understand this reply. Can u please elaborate the reply???
Apr 12 '07 #5
SammyB
807 Recognized Expert Contributor
Hi Sam,
I have already posted the message in the Forum http://www.thescripts. com/forum/thread629828.ht ml . As I did not get any reply, I sent u a private message. And I am also sorry for the late reply. I didn't understand this reply. Can u please elaborate the reply???
Sorry about the confusion. I didn't see your other post. I used a different reference: Microsoft Word x.x Object Library on the COM tab. I don't see Microsoft Office Interop, but I'm at work, stuck with Word 2000. I'll check when I get home, but it may be next week before I have time. I assume Interop is a DotNet thing, so could it be something simple like Microsoft.Offic e.Interop.Word. Range r = w[2]; instead of Microsoft.Offic e.Interop.Word. Range r = w.Item(2); Just a wild guess. --Sam
Apr 12 '07 #6
SammyB
807 Recognized Expert Contributor
Hi Sam,
I have already posted the message in the Forum http://www.thescripts. com/forum/thread629828.ht ml . As I did not get any reply, I sent u a private message. And I am also sorry for the late reply. I didn't understand this reply. Can u please elaborate the reply???
Yes, from http://msdn2.microsoft.com/en-us/lib...ds(vs.80).aspx, I think w[2] will give you a Range object for the third word in the document.
Apr 12 '07 #7
SammyB
807 Recognized Expert Contributor
Hi Sam,
I have already posted the message in the Forum http://www.thescripts. com/forum/thread629828.ht ml . As I did not get any reply, I sent u a private message. And I am also sorry for the late reply. I didn't understand this reply. Can u please elaborate the reply???
Well, I'm confused. I'm trying to verify if my replies are correct, but I cannot get the PIA installed. At home here I'm still running Office XP, but that's not a problem: I found the link to download the PIAs, http://www.microsoft.com/downloads/d...displaylang=en. This is a self-extracting zip, so I unzipped them and there is installation instructions in the Readme.htm. But the instructions assume that you have Visual Studio 2005 installed. How did you install the dll's with C# Express (which is what we both have)? Specifically, the install scripts need gacutil which is not on my machine. :confused: Sam
Apr 14 '07 #8
AricC
1,892 Recognized Expert Top Contributor
Sammy do you still need action on this thread?
Apr 15 '07 #9
SammyB
807 Recognized Expert Contributor
hi,
Please help me..
I am getting this error:
'Microsoft.Offi ce.Interop.Word .Words' does not contain a definition for 'Item'.

Code is:

Microsoft.Offic e.Interop.Word. Words w = wdDoc.Words;
Microsoft.Offic e.Interop.Word. Range r = w.Item(2);

I have included Microsoft.Offic e.Interop.Word dll in my project. And I am using Microsoft Visual C# 2005 Express Edition.

What would be the reason??
Is there anything I am missing???

thanks in Advance
Nelluru
I decided to see what would happen if I tried to use the Interop.Word dll without installation. Everything worked fine. I did have to browse for the dll, but I expected that. Maybe the "install" just makes the dll's visible on the References NET tab. Anyway, this code works for me:
Expand|Select|Wrap|Line Numbers
  1. const string DOC = @"C:\Documents and Settings\Sam\My Documents\Visual Studio 2005\Projects\WordAutomation\Demo.doc";
  2. object ms = System.Reflection.Missing.Value;
  3. //Word._Application wdApp = new Word.Application();
  4. Microsoft.Office.Interop.Word.Application wdApp = new Microsoft.Office.Interop.Word.ApplicationClass();
  5. wdApp.Visible = true;
  6. object oDoc = (object)DOC;
  7. Microsoft.Office.Interop.Word._Document wdDoc = wdApp.Documents.Open(ref oDoc, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms, ref ms);
  8. Microsoft.Office.Interop.Word.Words w = wdDoc.Words;
  9. Microsoft.Office.Interop.Word.Range r = w[2];
  10. MessageBox.Show(r.Text);
Does that help? --Sam
Apr 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2665
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a string of the form 100...0 using an arbitrary (but finite) number of zeros. Prove by induction that this transformation can not be performed infinitely many times, i.e. this sequence of transformations must terminate for any input string.
3
5012
by: % =joe % | last post by:
I cannot get this code to work. Very simple...I have three list menus. I want to do a check before the form submits to make sure that the value of the 3 fields is equal to 12. Here's my code... <script language="javascript"> <!-- function addListValues() {
1
1972
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a href="mailto:fred@blah.com"> emal me</a> woud be matched as expected, but so will:
2
1479
by: Willie | last post by:
I try to setup SQL Server to work with .NET Framework Anyone here willing to help? Step By Step Help Needed. Thanks
1
1734
by: BHPexpert | last post by:
Regular Expression help needed -------------------------------------------------------------------------------- I want to extract all text that is contained inside the brackets after the word INDIRECT. There must be at least one pair of parentheses, they may be multiple pairs for exampple, this string '=IF($B$9="Off",0,INDIRECT(ADDRESS(1(8),COLUMNS($A$41:C41),,,$B$9 )),()aaaa' has four bracket pairings until the initial "(" is...
1
1337
by: --== Alain ==-- | last post by:
Hi, Sorry to open a new post but i still do not have solved my issue with Collection property and i'm really blocked. I have a control which has a collection property. when an item of the collection property will be added, removed, and so on, i would like to refresh the control itself. Usually for that i use eventhandler in the set method of the property.
0
2573
by: Christopher | last post by:
Urgent Help Needed: The EPVH-1.1 Visual Hull Library. Dear All, I am a student doing research in computer vision. The EPVH-1.1 Visual Hull Library will really help a lot in my research. I did have this library before but I didn't keep my copy of this library because I always thought I could download it again form internet. However, the author of this library closed the download
1
2610
by: Joel Fireman | last post by:
Help Needed: Upgrade Fedora 4 / Apache 2 to PHP 5.2.x from 5.0.4 I've been testing Joomla as a content manager for the County offices, and it looks pretty good. Unfortunately, I decided to upgrade it from the 1.0.13 version to 1.5 as we get ready to go live with the web site... and the update installation gives an error in XML processing, which seems (from what I've been able to dredge up in forum discussions) to stem from a known bug in...
0
7978
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,...
0
8461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8448
jinu1996
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...
1
8126
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8317
tracyyun
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...
0
6796
agi2029
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...
1
5987
isladogs
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...
0
3948
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1313
bsmnconsultancy
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.