|
楼主 |
发表于 2015-1-6 13:40
|
显示全部楼层
搞了N久,问了N个人。
终于搞出来了。
原因:
1、调用时不要加() 。如:complex (tmu) 错误
2、嵌套表中的表前表后回车要处理好,直接删除是删除不了的。(先删除表,再删除回车)
3、嵌套域不是简单的嵌套,内嵌中并没有eq,所以用符号表示后,递归出来后,再化公式。
代码如下:- Sub a() '主函数
- Dim i As Integer, hcount As Integer
- Dim myTable As Table
-
- hcount = Me.Tables.Count
- For i = hcount To 1 Step -1
- Set myTable = Me.Tables(i)
- If myTable.Rows.Count = 2 And myTable.Columns.Count = 1 Then '繁分数递归
- complex myTable
- Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="eq " & Selection.Range.Text, PreserveFormatting:=False '增加一个新域
- End If
- Next i
- End Sub
- Sub complex(myT As Table) '繁分数递归
- Dim zi As String, mu As String
- myT.Cell(1, 1).Range.Find.Execute FindText:="([^13^11]){1,9}", MatchWildcards:=True, replacewith:="", Replace:=wdReplaceAll
- myT.Cell(2, 1).Range.Find.Execute FindText:="([^13^11]){1,9}", MatchWildcards:=True, replacewith:="", Replace:=wdReplaceAll
- If myT.Cell(1, 1).Tables.Count = 0 Then '分子递归
- zi = "\f(" & Replace(myT.Cell(1, 1).Range.Text, Chr(13) & Chr(7), "") & "," '分子去掉回车
- Else
- Dim tzi As Table
-
- For Each tzi In myT.Cell(1, 1).Tables
- complex tzi
- Next tzi
- zi = "\f(" & Replace(myT.Cell(1, 1).Range.Text, Chr(13) & Chr(7), "") & ","
- End If
- If myT.Cell(2, 1).Tables.Count = 0 Then '分母递归
- mu = Replace(myT.Cell(2, 1).Range.Text, Chr(13) & Chr(7), "") & ")" '分母去掉回车
- Else
- Dim tmu As Table
-
- For Each tmu In myT.Cell(2, 1).Tables
- complex tmu
- Next tmu
- mu = Replace(myT.Cell(2, 1).Range.Text, Chr(13) & Chr(7), "") & ")"
- End If
-
- myT.Select
- Selection.Tables(1).Delete '删除该表格
- Selection.MoveLeft
- Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
- If Selection.Range.Text = Chr(13) Then
- Selection.Delete
- End If
- Selection.InsertAfter Text:=zi & mu
- 'Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="eq " & zi & mu, PreserveFormatting:=False '增加一个新域
- End Sub
复制代码 |
|