Word automation/VB.NET

E

Elaine B.

VB.NET and automation of Word XP. I am doing Find/Replace
on a large document. Because of the nature of how this
document is built, I want to limit the Find/Replace to the
last two pages of a document. Someone kindly gave me this
code:

'Dim iP As Integer
'Dim sP As String
'Dim rR As Range

'rR = Selection.Range
'iP = ActiveDocument.ComputeStatistics(wdStatisticPages)
'sP = Trim(Str(iP - 1))
'Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext,
Name:=sP
'rR.Start = Selection.Start
'rR.End = ActiveDocument.Content.End
'rR.Select()
'With rR.Find
' .Text = "i"
' .Replacement.Text = "#"
' .Wrap = wdFindStop
' rR.Find.Execute(Replace:=wdReplaceAll)
'End With

The problem I am having is that this is written to run in
VBA behind a Word doc ("Active Document", "Selection",
etc). So I thought I could just tweak it to run in VB.NET
using a Word document object. The Selection object is
where I am having problems. I think I need to create a
Selection object (dim oSelection as selection) and then
set that object variable equal something. I dont want the
whole document, do I? Or do I? And if so, how do I do that?

oDoc is my Word doc object. It has no .Selection property.
So I am confused on how to get this code to run in VB.NET.
Can anyone advise?
 
C

Cindy M -WordMVP-

Hi Elaine,
The problem I am having is that this is written to run in
VBA behind a Word doc ("Active Document", "Selection",
etc). So I thought I could just tweak it to run in VB.NET
using a Word document object. The Selection object is
where I am having problems. I think I need to create a
Selection object (dim oSelection as selection) and then
set that object variable equal something. I dont want the
whole document, do I? Or do I? And if so, how do I do that?

oDoc is my Word doc object. It has no .Selection property.
So I am confused on how to get this code to run in VB.NET.
I'm not sure if this will kick things off, but Selection is a
property of the APPLICATION object.

Oh, and you probably want to specifically Dim oSelection as
WORD.Selection

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep
30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top