FindText Problem 
Author Message
 FindText Problem

I am still somewhat new to VBA coding. In the sample code below, I have a
character string that is longer than 256 characters.  I then want to search
for that string in a Word document.  However,  when the Execute statement is
executed, I get a runtime error saying the string is too long.  Through a
series of test, I determined the limitation is 256 characters using
FindText.  I know from documentation that a string can be over 65,000
characters long.

Does anyone know how I can resolve this problem?  Or, is there a better code
for doing this search without this limitation?

Sub SearchForText()
    TextToFind$ = " (a string here that is greater than 256 characters....)"
    With Word.Selection.Find
    .ClearFormatting
        .Execute FindText:=TextToFind$
        If .Found Then
            MsgBox  "String Found"
        Else
            MsgBox  "String Not Found"
        End If
    End With
End Sub

Thanks in advance.

    - Steve



Sun, 02 Nov 2003 11:05:02 GMT  
 FindText Problem
Hi Steve,

I believe this is a limitation of Word's FIND property, not of VBA.

Quote:
> However,  when the Execute statement is
> executed, I get a runtime error saying the string is too long.  Through a
> series of test, I determined the limitation is 256 characters using
> FindText.  I know from documentation that a string can be over 65,000
> characters long.

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 :-)



Sun, 02 Nov 2003 19:24:40 GMT  
 FindText Problem
Hi Steve,

If there aren't paragraph markers inside your find string you can loop
through the collection of paragraphs in your document and test their
content:

--------------------------------------------------------
Dim sTextToFind As String
Dim sTextToReplace As String
Dim oPara As Paragraph
Dim lParaCounter As Long

sTextToFind = "Find Text"
sTextToReplace = "ReplaceText"

Set oPara = ActiveDocument.Paragraphs(1)

For lParaCounter = 2 To ActiveDocument.Paragraphs.Count
  If oPara.Range.Text = sTextToFind & vbCr Then
    oPara.Range.Text = sTextToReplace & vbCr
  End If
  Set oPara = oPara.Next
Next lParaCounter

Set oPara = Nothing
--------------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to
the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/



Quote:
> I am still somewhat new to VBA coding. In the sample code below, I have a
> character string that is longer than 256 characters.  I then want to
search
> for that string in a Word document.  However,  when the Execute statement
is
> executed, I get a runtime error saying the string is too long.  Through a
> series of test, I determined the limitation is 256 characters using
> FindText.  I know from documentation that a string can be over 65,000
> characters long.

> Does anyone know how I can resolve this problem?  Or, is there a better
code
> for doing this search without this limitation?

> Sub SearchForText()
>     TextToFind$ = " (a string here that is greater than 256
characters....)"
>     With Word.Selection.Find
>     .ClearFormatting
>         .Execute FindText:=TextToFind$
>         If .Found Then
>             MsgBox  "String Found"
>         Else
>             MsgBox  "String Not Found"
>         End If
>     End With
> End Sub

> Thanks in advance.

>     - Steve



Sun, 02 Nov 2003 20:01:54 GMT  
 FindText Problem

Quote:
> Sub SearchForText()
>     TextToFind$ = " (a string here that is greater than 256
characters....)"
>     With Word.Selection.Find
>     .ClearFormatting

        ' I'm not WordChallenged, I'm WordClueless.  But ...
        ' If you can get the text you're searching into strSearchText then:
        If Instr(strSearchText, TextToFind$) > 0 then

Quote:
>             MsgBox  "String Found"
>         Else
>             MsgBox  "String Not Found"
>         End If

' Note:  Instr returns the position at which the text was found in the
string you're searching within.
Quote:
>     End With
> End Sub



Sun, 02 Nov 2003 21:00:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB crashes on using FindText

2. HELP: Common Dialog FindText and ReplaceText API Calls.

3. How to use the FindText and ReplaceText API

4. FindText & ReplaceText

5. FindText-commdlg32.dll

6. FindText/ReplaceText API call

7. FindText and ReplaceText functions

8. findtext api function

9. problems problems problems

10. Problems, Problems, Problems.....

11. Problem!Problem!Grid Problem!

12. Problems, problems, problems...

 

 
Powered by phpBB® Forum Software