我将文字添加到单词表中,对其进行排序并转移到列表框。我试着在桌子上使用不同的selection.clearformatting方法但是没有用。我需要从列表框中取出没有para的文本。符号和用于搜索文本。下面的Snippit
Do Until n = nmax
With Documents("lb2doc")
.Tables(1).Cell(i, 1).Range.Text = words(n)
.Tables(1).Cell(i, 2).Range.Text = disctime(n)
n = n + 1
i = i + 1
End With
Loop
Dim imax As Long
imax = i
i = 1
'sort table
Documents("lb2doc").Tables(1).Columns(1).Select
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Sort ExcludeHeader:=False, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderDescending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByCommas, SortColumn:=False, CaseSensitive:=False, _
LanguageID:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
Dim j As Long
j = 0
ListBox2.ColumnCount = 3
ListBox2.ColumnWidths = "0;60;20"
Do Until i = imax
ListBox2.AddItem
ListBox2.List(j, 1) = Documents("lb2doc").Tables(1).Cell(i, 1).Range.Text
ListBox2.List(j, 2) = Documents("lb2doc").Tables(1).Cell(i, 2).Range.Text
i = i + 1
j = j + 1
Loop
答案 0 :(得分:1)
段落标记是回车符,CHR(13)也是vb常量vbCr。只需将空白替换为两个插入的以下代码
ListBox2.List(j, 1) = Replace(Documents("lb2doc").Tables(1).Cell(i, 1).Range.Text, vbCr, "")
注意,如果您转到工具>选项菜单并选择在显示部分显示段落标记,您将能够在表格中看到段落标记。
答案 1 :(得分:1)
除了第一个提供的答案(对我不起作用)之外,您可以尝试通过设置起点和终点来获取文本范围。您的Do... Loop
将如下所示:
'...your code here
Do Until i = imax
ListBox2.AddItem
With Documents("lb2doc").Tables(1)
ListBox2.List(j, 1) = Documents("lb2doc").Range(.Cell(i, 1).Range.Start, _
.Cell(i, 1).Range.End - 1)
ListBox2.List(j, 2) = Documents("lb2doc").Range(.Cell(i, 2).Range.Start, _
.Cell(i, 2).Range.End - 1)
End With
i = i + 1
j = j + 1
Loop
'...rest of your code here