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 / November 2004

Tip: Looking for answers? Try searching our database.

Find and Replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick English - 30 Oct 2004 21:07 GMT
I have written a macro to replace specific text with the contents of a
textbox on a form. If the textbox contains multiple lines then the resulting
replacement does not have multiple lines. I searched the textbox contents
and the ascii characters 13 and 10 are at the end of each line (as they
should be). The replacement shows two null characters

How can I get multiple lines instead?

I should also mention that the replacements are, for the most part, taking
place in table cells

Rick English English Pool Consulting 1445 Twenty Eighth Street
rickenglish@cox.net tel: fax: mobile: 619-338-9197 619-338-9167 619-818-3052
Add me to your address book... Want a signature like this?
Rick English - 02 Nov 2004 19:34 GMT
Since I got no answer I can only assume that my problem is trivial,
unanswerable or, most likely,  that I did not give enough information. I'll
operate on the assumption

here is a typical call"

Call find_replace_text("&buyers_name", frmInitialdata.txtbuyersname.Text)

Here is the code

Sub find_replace_text(oldtext As String, newtext As String)
'
' find_replace Macro
Set myrange = ActiveDocument.Content
Call Check_Text(newtext)
   With myrange.Find
       .ClearFormatting
       .Text = oldtext
       With .Replacement
           .Text = newtext
       End With
       .Execute Replace:=wdReplaceAll, Format:=True
  End With
End Sub

' I wrote this sub to check to see if the correct ASCII characters were
being sent. Newstring should have CHR$(13) and CHR$(10) at the end of each
line.
' By stepping through the routine below, I confirmed that both those
characters were present. So this routine is going to be deleted
' So I know that the newtext string has the right content.
'

Sub Check_Text(newtext As String)
Dim text0 As String
Dim text1 As String
Dim index As Integer
text0 = ""
For index = 1 To Len(newtext)
   text1 = Mid$(newtext, index, 1)
   Select Case Asc(text1)
   Case Is = 13
   text0 = text0 & Chr(13)
   Case 32 To 127
   text0 = text0 & text1
   Case Else
   text1 = text1
   End Select
Next index
newtext = text0
End Sub

>I have written a macro to replace specific text with the contents of a
>textbox on a form. If the textbox contains multiple lines then the
[quoted text clipped - 10 lines]
> rickenglish@cox.net tel: fax: mobile: 619-338-9197 619-338-9167
> 619-818-3052 Add me to your address book... Want a signature like this?
Jay Freedman - 02 Nov 2004 22:22 GMT
Hi, Rick,

The problem is that the textbox and the document don't agree on what
constitutes an end-of-line character. The textbox does indeed use Chr$(13) &
Chr$(10). The document wants to see only the Chr$(13), and it displays the
Chr$(10) as a square.

Try this call instead of the one you have:

Call find_replace_text("&buyers_name", _
  Replace(frmInitialdata.txtbuyersname.Text, Chr$(10), ""))

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Since I got no answer I can only assume that my problem is trivial,
> unanswerable or, most likely,  that I did not give enough
[quoted text clipped - 65 lines]
>> 619-818-3052 Add me to your address book... Want a signature like
>> this?
 
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.