473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.Application
Dim doc As Word.Document
Dim range As Word.Range
Dim selection As Word.Selection

word = New Word.Application
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 NullReferenceException. 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 2168
"Al_P via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
news:ee******************************@DotNetMonste r.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.Application
Dim doc As Word.Document
Dim range As Word.Range
Dim selection As Word.Selection

word = New Word.Application
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 NullReferenceException. 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 "replacement text" in
test.doc)
Dim word As Word.Application
Dim doc As Word.Document
Dim range As Word.Range
word = New Word.Application
doc = word.Documents.Add("test.doc")
word.Visible = True
range = doc.Content
With range.Find
.ClearFormatting()
If range.Find.Execute(FindText:="find text") Then
range.Text = "replacement 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
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...
1
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...
4
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...
1
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...
10
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....
0
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...
2
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...
1
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....
3
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 ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.