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 / May 2008

Tip: Looking for answers? Try searching our database.

Replace function and carriage returns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bz - 28 May 2008 18:45 GMT
I am using Word 2000 and XP.

I have a table containing formfields.  In a macro I output the contents of
selected formfields to a text file and then later insert this file into a new
Word document and use the text to table conversion to create a table.
Sometimes, if one of the formfields contains carriage returns, the result is
that the text following the carriage return begins on the first column of the
next row (i.e. not the next line in the same cell).

The best solution would be to have the carriage returns work correctly
(within the same cell).

An alternative is to strip out the carriage returns.  I  tried doing this
using the Replace function.  Before writing out to the text file, I copy the
.result of the formfield to a string
(myString=ActiveDocument.FormFields("myString").Result).
I then try to replace: myString=Replace(myString,"^p","").  Also tried with
myString=Replace(myString,Chr(13),"").

The result is that no replacement is made.  This is the case no matter what
I try to use as a replacement string.

Thanks in advance for any help, bz
StevenM - 28 May 2008 19:13 GMT
To: Bz,

Perhaps you need something like:

'****
'*
'* Function: StripCr
'*
'* When a string ends with a "Carriage Return" marker, or a "Carriage Return"
'* and "Line Feed" markers, this function will strip them off from a string.
'*
'****
Function StripCr(ByVal sStr As String) As String
   Dim nPos As Long
   nPos = InStr(sStr, Chr(13))
   If nPos > 0 Then
       sStr = Left(sStr, nPos - 1)
   End If
   StripCr = sStr
End Function

Steven Craig Miller

> I am using Word 2000 and XP.
>
[quoted text clipped - 19 lines]
>
> Thanks in advance for any help, bz
bz - 30 May 2008 21:59 GMT
Thanks very much for your help, which pointed me in the right direction.
I used an extension of what you suggested:

Function StripCr(ByVal sStr As String) As String

 Dim nPos As Long
 nPos = InStr(sStr,Chr(13))

 Do While nPos > 0
   sStr = Left(sStr,nPos-1) & " " & Right(sStr, Len)sStr-nPos))
   nPos = InStr(sStr,Chr(13))
 Loop
 StripCr=sStr

End Function

> To: Bz,
>
[quoted text clipped - 42 lines]
> >
> > Thanks in advance for any help, bz
 
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.