Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Find a paragraph that is also in autotext

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lesley Regan - 27 Jun 2005 20:26 GMT
After searching, browsing, finding out all kinds of things about autotext, I
cannot tell if I can do what I'm about to ask about.

If somebody could help with syntax or tell me it can't be done, I'll either
start coding or stop trying to find out!

I am running XP.

I have a long paragraph that is supposed to be included in every letter we
create.  I'd like to program a search for the paragraph (in documents being
reused) and then either insert the paragraph if it's not found, or not insert
it, if it's already in the document.

It makes sense to have a paragraph available in a globally accessible
template as Autotext with a unique name of 2 or 3 words, like
autoLetterInsert.

OK, now, I found code that allows me to INSERT autotext, and code that lets
me set the value of an autotext entry, and similar code, but can I put
together Find with Autotext.Value? (pseudocode):

Something like:
clearformatting....
.
.

FindText = AutoTextEntries(autoLetterInsert).Value

If somebody could help I'd appreciate it.

Thank you, merci, gratiam tibi,
Regards, Lesley Regan
Jean-Guy Marcil - 28 Jun 2005 03:06 GMT
Lesley Regan was telling us:
Lesley Regan nous racontait que :

> After searching, browsing, finding out all kinds of things about
> autotext, I cannot tell if I can do what I'm about to ask about.
[quoted text clipped - 28 lines]
> Thank you, merci, gratiam tibi,
> Regards, Lesley Regan

If the documents are not too long, you could dump the document text in a
string variable, dump the paragraph text in another string variable, finally
check if variable 2 is in variable 1 with InStr.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Lesley Regan - 28 Jun 2005 14:00 GMT
Signature

Regards, Lesley

> Lesley Regan was telling us:
> Lesley Regan nous racontait que :
[quoted text clipped - 35 lines]
> string variable, dump the paragraph text in another string variable, finally
> check if variable 2 is in variable 1 with InStr.

Bonjour, Jean-Guy,

Thank you for your suggested solution.  I haven't done Word programming  
long enough to think of a string comparison in this case, but Instr seems to
be a good compromise.   I'm comfortable with strings.  I can't imagine that
these letters are long enough to be classified as "long documents", but  one
can never be sure.  I'll do some timing tests.

Cheers!

Lesley
Jean-Guy Marcil - 28 Jun 2005 16:19 GMT
Lesley Regan was telling us:
Lesley Regan nous racontait que :

> Bonjour, Jean-Guy,
>
[quoted text clipped - 4 lines]
> classified as "long documents", but  one can never be sure.  I'll do
> some timing tests.

I think that any string comparison will be way faster than most collection
iteration. (As in: For each para in ActiveDocument... )

'_______________________________________
Dim docContentStr As String
Dim paraStr As String

paraStr = "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog.  " _
   & "The quick brown fox jumps over the lazy dog."
'Or
'paraStr = NormalTemplate.AutoTextEntries("autoLetterInsert").Value
'If the autotext is in Normal.dot

docContentStr = ActiveDocument.Range.Text

If InStr(1, docContentStr, paraStr) > 0 Then
   MsgBox "String found!"
Else
   MsgBox "String not found!"
End If
'_______________________________________

I tried the above with a 173-page document containing over 24,000 characters
and over 7,500 paragraphs. The result was nearly instantaneous.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Lesley Regan - 28 Jun 2005 16:32 GMT
> Lesley Regan was telling us:
> Lesley Regan nous racontait que :
[quoted text clipped - 40 lines]
> I tried the above with a 173-page document containing over 24,000 characters
> and over 7,500 paragraphs. The result was nearly instantaneous.

I am so impressed, and so grateful.  Thank you very much!

lr
Lesley Regan - 28 Jun 2005 16:44 GMT
> > Lesley Regan was telling us:
> > Lesley Regan nous racontait que :
[quoted text clipped - 44 lines]
>
> lr

P.S. I think I need to practice my "for each" loops though, so I'm going to
try that way as an exercise.

keep cool, everybody,

lesley
Helmut Weber - 28 Jun 2005 03:16 GMT
Hi Lesley,

won't work anyway, as the length of the search string is limited to
255 characters anyway, whereby I assume, that your long paragraphs are
longer than that.

For searching for longer strings, see:

http://gregmaxey.mvps.org/Find_Long_String.htm

If the docs are rather small, you may rather use
something like (untested):
dim oPrg as paragraph
for each prg in activedocument.range.paragraphs
if oprg.range.text = AutoTextEntries(autoLetterInsert).Value then
next

Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Lesley Regan - 28 Jun 2005 13:55 GMT
Signature

Regards, Lesley

> Hi Lesley,
>
[quoted text clipped - 19 lines]
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"

Ah, Helmut, I like this idea.  I shall try it.  (Yes, I did know the
limitation of the search string, but somehow hoped it didn't apply to
autotext.)

Thank you for your idea and explanation,

Lesley
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.