Finding location of text

Finding location of text

Post by Cynthi » Thu, 07 Mar 2002 07:56:02



I am using an "insertafter" to place text into a document.
Once in the document, if it is a reference (preset flag) I
need to find the location of that text in that document I
just placed and put a box around the first (or more if
double or triple digit numbers) number.
First question, is there a property to help me select the
first character in the string to know where to start
drawing the textbox? What property in AddTextBox allows
you to utilize a known location?

Thank you
Cynthia

 
 
 

Finding location of text

Post by Cindy Meister -WordMVP » Fri, 15 Mar 2002 19:52:13


Hi Cynthia,

1) If all you want is a line-box around these characters, you
don't want to be inserting a TextBox
2) You'll be able to work most efficiently if you use a range
object variable and assign what you're inserting to its
Text property. Then you can manipulate the characters
directly. Something like
    Dim rng as Word.Range

    set rng = ActiveDocument.Range
    rng.Collapse wdCollpaseEnd
    rng.Text = "123 etc."
    rng.End = rng.Start + 3
    rng.Bold = True

Quote:> I am using an "insertafter" to place text into a document.
> Once in the document, if it is a reference (preset flag) I
> need to find the location of that text in that document I
> just placed and put a box around the first (or more if
> double or triple digit numbers) number.
> First question, is there a property to help me select the
> first character in the string to know where to start
> drawing the textbox? What property in AddTextBox allows
> you to utilize a known location?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

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

 
 
 

1. Find various text and copy the found text into different document

Hi,

I am a newbie and any help is really appreciated.

I have a word document that contains "Tags" with codes in
them. I need to:
1. Open Word.
2. Search the entire document for the tags.
3. Copy all of the text with the tag (Tag = <Tag_abcd>)
   to a different document .txt file.

The new document/end result should look like this:

<Tag_abcd>
<Tag_efgh>
<Tag_ijkf>
<Tag_abcd>

What I have so far: The macro only copies one line to a
new document and stops.

Option Explicit
Dim objWordApp As Word.Application
Dim objWordDoc As Word.Document
Dim path As String
Private Sub Command1_Click()
'Create a new instance of Word
Set objWordApp = New Word.Application
Set objWordDoc = _
    objWordApp.Documents.Open(File1.path & "\" &          
File1.FileName)
    objWordApp.Visible = True
Do
         Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "<Tag=C:\FAST_CSR\RTF-Test\SampleD1a.RTF>"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False

    End With
    Selection.Find.Execute

    If Selection.Find.Found Then

    Selection.Copy

    ChangeFileOpenDirectory "C:\"
    Documents.Open FileName:="test.doc",
ConfirmConversions:=False, ReadOnly:= _
        False, AddToRecentFiles:=False,
PasswordDocument:="", PasswordTemplate:= _
        "", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto
    Selection.MoveDown Unit:=wdLine, count:=1
    Selection.TypeParagraph
    Selection.Paste

End If

Loop Until Not Selection.Find.Found
End Sub

Thanks again.... Lisa

2. Your own Homepage $99

3. location on screen of the word found in "Find"

4. link to relative path in HTML assistance needed!

5. Office98 for Mac -- cannot Customize Office Manager (G4 with MacOS 9)

6. Location Location Location

7. Office startup

8. controlling location of text label for an text box

9. Using a text box to find and find next in fields

10. find text command will not stop finding when you click "next page" arrow

11. Find doesn't find text inside field result when wildcards are enabled

12. Find Replace - how to add to the find text