473,890 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automating Word - Problem with .Find

I have:
Win2K
Office2000
Working in VB.Net (2003)
My .Net project has a reference to Word 9.0

Instantiating things in a simple and straightforward manner:
Dim word as Word.Applicatio n
Dim doc As Word.Document
Dim range As Word.Range
Dim selection As Word.Selection

word = New Word.Applicatio n
doc = word.Documents. Add("<path to a .dot>")

Everything works fine, until I try to do a Find:
range.Find.Text = "Your string here"

The Find object returns a NullReferenceEx ception. I've tried every
variation I can think of using Find, including using the Selection.Find
object. The same code works okay in VB6, although that's probably
irrelevent except for verifying my syntax is okay.

I've Googled this issue to the point of exhaustion, and haven't been able
to find an answer. Anybody have any ideas?

Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
2 2185
"Al_P via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in
news:ee******** *************** *******@DotNetM onster.com:
I have:
Win2K
Office2000
Working in VB.Net (2003)
My .Net project has a reference to Word 9.0

Instantiating things in a simple and straightforward manner:
Dim word as Word.Applicatio n
Dim doc As Word.Document
Dim range As Word.Range
Dim selection As Word.Selection

word = New Word.Applicatio n
doc = word.Documents. Add("<path to a .dot>")

Everything works fine, until I try to do a Find:
range.Find.Text = "Your string here"

The Find object returns a NullReferenceEx ception. I've tried every
variation I can think of using Find, including using the Selection.Find object. The same code works okay in VB6, although that's probably
irrelevent except for verifying my syntax is okay.

I've Googled this issue to the point of exhaustion, and haven't been able to find an answer. Anybody have any ideas?

Thanks


you haven't set range to anything. Try
range = doc.content

example (find text "find text" and replace with "replacemen t text" in
test.doc)
Dim word As Word.Applicatio n
Dim doc As Word.Document
Dim range As Word.Range
word = New Word.Applicatio n
doc = word.Documents. Add("test.doc")
word.Visible = True
range = doc.Content
With range.Find
.ClearFormattin g()
If range.Find.Exec ute(FindText:=" find text") Then
range.Text = "replacemen t text"
End If
End With
When range finds something the range is set to that something, which is
why the replacement text is assigned to range.text. If you want to find
again you need to reset the range to the document content.
Nov 21 '05 #2
Yes- thanks for the note. You're right about the range object.

The underlying problem, which I discovered this morning, was a corrupted
Word typelib (msword9.olb). If you care to read further, go to Microsoft
and find Article 292744.

Thanks for the reply.

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #3

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

Similar topics

0
1645
by: gizmo | last post by:
We have a requirement to initiate more than one instance of an application using the filenames. (the example below will start two instances of MS Word). The problem is that we need to close each word document individually, but this does not appear possible using the Process object. When I run the example below the process object "p" can be viewed using Quick Watch however process object p2 is displayed as undefined. This appears to be...
1
2714
by: John Davy | last post by:
I am trying to set up a mail merge by automation using a text file as the data source but I keep getting the message "Requested object is not available" and the debugger stops on the opendatasource line (code below) (I am VERY new to c# so this is a bit difficult for me at the moment) I am using win xp and office xp 2003 (word 11) I have installed the PIA for office as per Microsoft KB
4
3331
by: Rob | last post by:
Here is my issue: I am trying to load word through vb.net code behind an ASP.NET webform. I know it is possible to use the Automation and COM classes because a co-worker has it working on his machine with an identical setup. I am referencing the Interop.Word references. I have read the Considerations Article Microsoft has written about using Word at the Server level, I am aware of the security risks involved as well. However, that all...
1
12259
by: John Welch | last post by:
I'm trying to use the Mergit() function from the MS Knowledge base article to merge data from a query or table in my Access 2000 mdb into an existing word merge document. Every time it runs it brings up the dialog "Confirm Data Source", and asks if I want to use OLE, DDE, or ODBC. If I say ODBC, it then asks me for the table name. If I do all that, the merge works correctly, but I don't want users to have to do all that. I thought the...
10
2050
by: mc | last post by:
I've know that Microsoft don't currently recommend this process, what I'm trying to find out is why? This is a feature that I've used (with Classic ASP) in the past with a great deal of success. Regards MC
0
1102
by: pbrady1970 | last post by:
I would like to know if it is possible to create an instance of Word and pass the "-a" parameter/switch (Start Word and prevent add-ins ) CDispatch oWord; try { CP(_T("GenerateWithWord ------> Attempting to create Word Application")); oWord.CreateInstance("Word.Application"); } catch (...)
2
1841
by: chutney | last post by:
Dear all, please excuse the fact that this is not an explicit problem I have, but more of a general query. I have an Access database (2003) with a load of contact details in it. Including various fields for each contact, such as services they offer, where they are, main contact name etc. Some of these contact details will be out of date and I want to make sure that all the contact details are up-to-date. I am in the process of setting...
1
2058
by: TommyGunn | last post by:
Hi everyone, Is there anyway to automatically put Access data into Mail Merge in an existing Word doc with content? I have bits and pieces of this done, but I can't seem to put it all together. I am able to manually export an Access Query to Word, and the mail merge works fine. I am also able to open Word from Access, but unfortunately the Mail Merge data does not get updated since the manual export (thinking a few days later when the...
3
1440
by: MickT | last post by:
Hello, I am coding in VB.NET with Option Strict ON in Visual Basic 2008 Express My code is to automate WORD from a VB.NET windows application, as I used to in VB6. Part of my code is Dim oWord As Word.Application
0
9978
marktang
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...
0
10819
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
10923
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
10462
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
9633
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...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3277
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.