大众计算机学习网

专门提供各种电脑教程

如何让Word文档内容折叠之VBA源代码

Admin | 2008-9-11 20:22:07 | 被阅次数 | 8235

Option Explicit
Sub Example1()
    Dim MyRange As Range
    With Selection
        ActiveDocument.AttachedTemplate.AutoTextEntries("展开").Insert .Range
        .Paragraphs(1).Next.Range.Font.Hidden = False
    End With
End Sub
'----------------------
Sub Example2()
    Dim MyRange As Range
    With Selection
        ActiveDocument.AttachedTemplate.AutoTextEntries("折叠").Insert .Range
        Set MyRange = ThisDocument.Range(.Paragraphs(1).Next(1).Range.Start, .Paragraphs(1).Next(2).Range.End)
        MyRange.Font.Hidden = True
    End With
End Sub
'----------------------

Private Sub Document_Close()
  Options.ButtonFieldClicks = 2
End Sub
'----------------------

Private Sub Document_New()
  Application.OrganizerCopy
End Sub
'----------------------

Private Sub Document_Open()
    With ActiveDocument.ActiveWindow
        .View.ShowAll = False
        .View.ShowHiddenText = False
    End With
    Options.ButtonFieldClicks = 1
End Sub

  网上抄的,呵呵!