以下代码供参考,特别是双行合一,需要楼主特别关注并测试。
'* +++++++++++++++++++++++++++++
'* Created By I LOVE YOU WORD!@ExcelHome 2006-2-23 20:10:03
'仅测试于System: Windows NT Word: 11.0 Language: 2052
'№ 0021^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------
Option Explicit
Sub Example()
Dim i As Range, myDoc As Document
Dim myString As String, N As Integer, M As Integer
Dim L As Integer
Application.ScreenUpdating = False
With ThisDocument
For Each i In .Characters
With i
'判断是否有边框
If .Font.Borders(1).LineStyle <> wdLineStyleNone Then
If N = 0 Then '边框起始位置加上开始标记
myString = myString & "[BOX(]" & .Text
Else
myString = myString & .Text
End If
N = N + 1
'如果N>0并且此时没有字体边框时,加上结束标记
ElseIf N > 0 And .Font.Borders(1).LineStyle = wdLineStyleNone Then
myString = myString & "[BOX)]" & .Text
N = 0
'判断底纹
ElseIf .Font.Shading.Texture <> wdTextureNone Then
If M = 0 Then
'加上起始底纹标记
myString = myString & "[DW(]" & .Text
Else
myString = myString & .Text
End If
M = M + 1
ElseIf M > 0 And .Font.Shading.Texture = wdTextureNone Then
'加上底纹结束标记
myString = myString & "[DW)]" & .Text
M = 0
'判断双行合一
ElseIf .TwoLinesInOne <> wdTwoLinesInOneNone Then
If L = 0 Then '起始标记
myString = myString & "↑(" & .Text
ElseIf .Text = " " Then '空格作为双行合一的分隔符,必须!
myString = myString & ")↓(" '结束标记
Else
myString = myString & .Text
End If
L = L + 1
ElseIf L > 0 And .TwoLinesInOne = wdTwoLinesInOneNone Then
myString = myString & ")" & .Text
L = 0
Else
myString = myString & .Text
End If
End With
Next
End With
' Debug.Print myString
Set myDoc = Documents.Add
myDoc.Content.InsertAfter myString
Application.ScreenUpdating = True
End Sub |