Can get carriage return to work
Can get carriage return to work
(OP)
I have an automated Word document that looks to an Excel file where I am saving lines of text. I use strVariable = ExcelSheet.Cells(i, 2) to get the text in the file but it doesn't see the carriage returns. I've tried vbCr and vbLf and Chr$(10) but nothing seems to work. I have
"this bit is text" & CHR$(13) & "this bit is more text"
but it doesn't create the line feeds for some reason. Any suggestions?
"this bit is text" & CHR$(13) & "this bit is more text"
but it doesn't create the line feeds for some reason. Any suggestions?





RE: Can get carriage return to work
CODE
RE: Can get carriage return to work
RE: Can get carriage return to work
I the data in the first column matches strVaraible then get the data in second column.
Found = false
For i = 5 To 50
If Excelsheet.Cells(i, 1) = "" Then Exit For
If Excelsheet.Cells(i, 1) = strVariable Then
strResults = Excelsheet.Cells(i, 2).Value
If Found = True Then
strResults = strResults & Chr$(10) & Excelsheet.Cells(i, 2).Value
Else
strResults = strResults & Excelsheet.Cells(i, 2).Value
End If
Found = True
End If
Next i
RE: Can get carriage return to work
RE: Can get carriage return to work
RE: Can get carriage return to work
The boolean "found" can never be set to true because the assignment stated "found = true" is inside the conditional "If found = true".
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Can get carriage return to work
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Can get carriage return to work
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: Can get carriage return to work
Selection.TypeText Text:="first part"
Selection.TypeParagraph
Selection.TypeText Text:="second part"
So your code would look something like this:
CODE
Dim i As Integer
a = [a1].Value
parts = Split(a, vbLf)
For i = 0 To UBound(parts)
Selection.TypeText Text:=parts(i)
Selection.TypeParagraph
Next i
Cheers,
Joerd
Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: Can get carriage return to work
How about vbCrLf?
RE: Can get carriage return to work
RE: Can get carriage return to work
"this bit is text" vbCr "this bit is more text
and not breaking it down into separate lines>
Could it have something to do with the quotes?
RE: Can get carriage return to work
Maybe it's the "ding" that the old manual typewriters used to make when you got near the end of the writing width. (Just before you slapped to platten back across to the left.)
RE: Can get carriage return to work
RE: Can get carriage return to work
RE: Can get carriage return to work
Public Sub ReplaceCarriageReturns()
Dim i As Integer
Dim L As Integer
Dim X As Integer
For i = 1 To 5
X = InStr(strATextValue, " & vbcr & ")
If X = 0 Then Exit Sub
If X > 0 Then
L = Len(strATextValue)
strATextValue = Left(strATextValue, X - 1) & vbCr & Right(strATextValue, L - (X + 9))
End If
Next i
End Sub
Thanks for the ideas
RE: Can get carriage return to work
strATextValue = Replace(strATextValue, vbLf, vbCr)
Modify as needed, it's pretty flexible.
Cheers,
Joerd
Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.
RE: Can get carriage return to work
That's a new command to me and it did exactly what i was looking for.