word保留格式简体转换成繁体宏

Sub 保留格式简体转换成繁体()

'Windows("50菩提道次第广论第50讲(修订稿).doc").Activate
If Documents.Count < 2 Then
        MsgBox ActiveDocument.Name & ":点击确定开始转换成繁体"
    Else
        MsgBox "为防止转换错误,请只打开需要转换的一个word文档"
End If

If ActiveDocument.TrackRevisions = True Then
    ActiveDocument.TrackRevisions = False
End If

index_c = 0
index_cend = 1
index_n = 1
index_nend = 2
i = 0
Dim rngDoc As Range
Dim nextRng As Range
Dim f As Font
Dim f2 As Font
dend = ActiveDocument.Content.End

While index_nend < dend

Set rngDoc = ActiveDocument.Range(Start:=index_c, End:=index_cend)
Set f = rngDoc.Font.Duplicate
Set nextRng = ActiveDocument.Range(Start:=index_n, End:=index_nend)
Set f2 = nextRng.Font.Duplicate

If (f.Name = f2.Name) And (f.Color = f2.Color) And (f.Bold = f2.Bold) And (f.Size = f2.Size) And (f.Italic = f2.Italic) And (index_nend + 1) < dend Then
    index_n = index_n + 1
    index_nend = index_nend + 1
Else
    index_cend = index_nend
    Set rngDoc = ActiveDocument.Range(Start:=index_c, End:=index_cend)
    Set f = rngDoc.Font.Duplicate
    rngDoc.Select
    Selection.Range.TCSCConverter WdTCSCConverterDirection:= _
        wdTCSCConverterDirectionSCTC, CommonTerms:=True, UseVariants:=True
        
    With Selection.Range.Font
    .Bold = f.Bold
    .Name = f.Name
    .Size = f.Size
    .Italic = f.Italic
    .Color = f.Color
    End With
    index_c = index_cend
    index_cend = index_cend + 1
    index_n = index_cend
    index_nend = index_nend + 1
End If

Wend

Call footnote_gb2big5
If ActiveDocument.TrackRevisions = False Then
    ActiveDocument.TrackRevisions = True
End If

MsgBox "文档转换完成"
End Sub

Sub footnote_gb2big5()
'ScreenUpdating = False

'Windows("50菩提道次第广论第50讲(修订稿).doc").Activate
Dim myend As Range
Dim rngDocFoot As Range
Dim f As Font

i = 0

While i < ActiveDocument.Footnotes.Count
    ActiveDocument.Footnotes(i + 1).Range.Select
    Set rngDocFoot = ActiveDocument.Footnotes(i + 1).Range
    rngDocFoot.Select
    Set f = rngDocFoot.Font.Duplicate

    Selection.Range.TCSCConverter WdTCSCConverterDirection:= _
        wdTCSCConverterDirectionSCTC, CommonTerms:=True, UseVariants:=True
    i = i + 1

    With Selection.Font
        .Bold = f.Bold
        .Name = f.Name
        .Size = f.Size
        .Italic = f.Italic
        .Color = f.Color
    End With
Wend

End Sub

猜你喜欢

转载自my.oschina.net/jianhui1980/blog/1623763