我正在尝试从带有格式化文本的文本框中删除回车符:
For i = ThisShape.TextFrame2.TextRange.Runs.Count To 1 Step -1
ThisText = ThisShape.TextFrame2.TextRange.Runs(i).Text
ThisText = Replace(ThisText, Chr(13), "")
ThisShape.TextFrame2.TextRange.Runs(i).Text = ThisText
Next i
由于某些奇怪的原因,文本框仍然带有回车符。 任何帮助将不胜感激。
大卫
答案 0 :(得分:0)
CLEAN
函数很少使用,因此经常被遗忘。 CLEAN
从给定文本中删除不可打印的字符(ASCII 0到31)。您可以在VBA中使用它:
myStr = Application.WorksheetFunction.Clean(myStr)
...或作为Excel工作表功能:
=CLEAN(A1)
Sub cleanDemo()
Dim mystr As String
'populate string with linefeeds and carriage returns.
'note: vbLf = chr(10): vbCr = chr(13) : vbCrLf = vbCr+vbLf
mystr = "A" & vbLf & "B" & vbCr & "C" & vbCrLf & "D"
'display string and it's length
MsgBox mystr, , "myStr is " & Len(mystr) & " char long."
'remove ASCII 0 through 31
mystr = Application.WorksheetFunction.Clean(mystr)
'display string and it's length
MsgBox mystr, , "myStr is " & Len(mystr) & " char long."
End Sub
...返回:
该过程列出了在指定字符串中找到的字符及其代码:
Sub showAllChars(strIn as String)
'Lists all ASCII character codes used in the specified string.
'Adaptable to UNICODE by changing Asc to AscW and Chr to ChrW
Dim strIn As String, c As String, p As Long
For p = 1 To Len(strIn)
c = Mid(strIn, p, 1)
Debug.Print "Pos#" & p & ": Chr(" & Asc(c) & ") =[";
Select Case Asc(c)
Case 10
Debug.Print "LF]", ;
Case 13
Debug.Print "CR]", ;
Case Else
Debug.Print c & "]", ;
End Select
If p / 5 = p \ 5 Then Debug.Print
Next p
Debug.Print "Done. (Length=" & Len(strIn) & ")"
End Sub
示例输出:
Pos#1: Chr(65) =[A] Pos#2: Chr(66) =[B] Pos#3: Chr(13) =[CR]
Pos#4: Chr(67) =[C] Pos#5: Chr(63) =[?] Pos#6: Chr(68) =[D]
Pos#7: Chr(17) =[] Pos#8: Chr(69) =[E] Pos#9: Chr(70) =[F]
Pos#10: Chr(63) =[?] Pos#11: Chr(71) =[G] Pos#12: Chr(10) =[LF]
Pos#13: Chr(72) =[H] Pos#14: Chr(73) =[I] Done. (Length=14)
Office.com:CLEAN Function (Excel/VBA)
ascii.cl:ASCII Codes Tables
维基百科:ASCII