这种形式的“表格”,我在论坛,总共见到三次。 要不是程序自动生成的,必是“牛”人所为。 如果“牛”人能做到如此图形精确组合,必是高手,所以还是不要猜是哪位高手所为,我以为,程序导出或者生成的可能性更高一些。 我使用“擦边球”的方式进行了一次尝次,这也是我以前一直想的方法,如果是多页,可以分页进行或者其他方式,原理相通。 Option Explicit Option Compare Text Sub Test() Dim oShape As Shape, N As Single, myString As String Dim newDoc As Document, myRange As Range On Error Resume Next '忽略错误 '取消图形组合 ActiveDocument.Content.ShapeRange.Ungroup For Each oShape In ActiveDocument.Shapes '遍历图形 If oShape.TextFrame.HasText = True Then '如果具有文字(也可另行判断) N = oShape.Left + oShape.Top * 100 '此处作一埋伏,即以顶部距离为主要"列"判断依据 myString = myString & N & "|" & VBA.Replace(oShape.TextFrame.TextRange.Text, " ", "") End If Next myString = VBA.Mid(myString, 1, Len(myString) - 1) '去除最后一个段落标记(注意文本框返回时已具有段落标记) Set newDoc = Documents.Add '新建一个空白文档 Set myRange = newDoc.Content myRange.Text = myString '插入文本 '以数字方式进行排序 myRange.Sort Separator:="|", SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending With myRange.Find '删除新排序的数据文本 .ClearFormatting .MatchWildcards = True .Execute findtext:="[0-9]@|", replacewith:="", Replace:=wdReplaceAll End With Set myRange = newDoc.Content '重新定义一个RANGE对象 With myRange '转为表格并设置格式 .ConvertToTable(Separator:=wdSeparateByParagraphs, numcolumns:=2).Style = "网格型" .CharacterWidth = wdWidthHalfWidth .Font.Name = "华文细黑" .Font.Size = 12 End With End Sub '----------------------
|