Find&replace-code 
Author Message
 Find&replace-code

Hi

I'm looking for some example code for the following problem:

I would like to embed the following syntax in my document to indicate that I
want to insert a text file at a certain point, lik this:

"I would like to insert some text <<FILEA>> and some other text here
<<FILEB>>"

I know I will have to scan for the "<<" text string, then for the ">>"
string, picking up the file name (FILEA), deleting the <<FILEA>> and then
comes the insertfile. Then we have to go on for the next sequence....
Btw. I don't intend to have such references (<<filex>>) within the files I'm
inserting.

I would be very happy if someone could come up with sample code that can be
modified/used for this purpose.

Regards

Reidulv Halsnes


Seniorkonsulent, Norsk Informasjonssikkerhet AS
Postboks 826, Her?ya
N-3903 Porsgrunn
www.informasjonssikkerhet.no
Tlf. jobb:  35 57 26 31,  Mob. tlf: 905 36 948
Fax:        903 82 532,   Tlf. priv: 35 51 27 84



Fri, 26 Jul 2002 03:00:00 GMT  
 Find&replace-code
Hi reid,

Here's a snippet of code from my website, http://www.wordsite.com, that
seems to answer your needs.

Replace each instance of the text string "Document One" with the contents of
a file called c:\test\Doc1.doc.

Code:
This code is provided for illustrative purposes only and is not warranted to
be suitable for any particular business purpose. The code may be freely
copied for any lawful business purpose.
Sub ReplaceTagWithFile()
Selection.HomeKey unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Document One"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute()
Selection.InsertFile _
FileName:="c:\test\Doc1.doc", Range:="", _
ConfirmConversions:=False, _
Link:=False, _
Attachment:=False
Wend
End Sub

--
Bill Coan
Microsoft Word MVP
Neenah WI 54956 USA
http://www.wordmacros.com
. . .

Quote:
> Hi

> I'm looking for some example code for the following problem:

> I would like to embed the following syntax in my document to indicate that
I
> want to insert a text file at a certain point, lik this:

> "I would like to insert some text <<FILEA>> and some other text here
> <<FILEB>>"

> I know I will have to scan for the "<<" text string, then for the ">>"
> string, picking up the file name (FILEA), deleting the <<FILEA>> and then
> comes the insertfile. Then we have to go on for the next sequence....
> Btw. I don't intend to have such references (<<filex>>) within the files
I'm
> inserting.

> I would be very happy if someone could come up with sample code that can
be
> modified/used for this purpose.

> Regards

> Reidulv Halsnes


> Seniorkonsulent, Norsk Informasjonssikkerhet AS
> Postboks 826, Her?ya
> N-3903 Porsgrunn
> www.informasjonssikkerhet.no
> Tlf. jobb:  35 57 26 31,  Mob. tlf: 905 36 948
> Fax:        903 82 532,   Tlf. priv: 35 51 27 84



Fri, 26 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Find & Replace Problem - ACC97

2. Find& replace one by one

3. Find & Replace using input box

4. FIND & REPLACE

5. Multiple find & replace

6. find & Replace with wild cards and patterns

7. find/replace on headers&footers

8. Excel macro to find&replace in MSWord

9. Find&Replace Tab

10. Global Find & Replace

11. Find & replace question

12. Advanced Find & Replace

 

 
Powered by phpBB® Forum Software