以下是引用huposhhy在2004-7-20 10:55:00的发言:
我想在Word中实现这样的功能:
我将某篇文章的文字定义成三种不同颜色的三段,比如黑、兰和红色,我想用VBA实现四个按钮:点击按钮1隐藏兰色文字段,点按钮2隐藏红色文字段,点击按钮3显示兰字段,点击按钮4显示红字段。
各位一定要帮啊,在些先谢谢了!
AmzwGa8X.zip
(10.4 KB, 下载次数: 19)
请在运行本程序前将宏安全性设为低。
主要代码如下,代大家参考:
Public RedRange As Range, GreenRange As Range
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "隐藏红色段落" Then
RedRange.Font.Hidden = True
CommandButton1.Caption = "显示红色段落"
Else
RedRange.Font.Hidden = False
CommandButton1.Caption = "隐藏红色段落"
End If
End Sub
Private Sub CommandButton2_Click()
If CommandButton2.Caption = "隐藏绿色段落" Then
GreenRange.Font.Hidden = True
CommandButton2.Caption = "显示绿色段落"
Else
GreenRange.Font.Hidden = False
CommandButton2.Caption = "隐藏绿色段落"
End If
End Sub
Private Sub UserForm_Activate()
Set RedRange = ActiveDocument.Paragraphs(1).Range
Set GreenRange = ActiveDocument.Paragraphs(3).Range
Me.Caption = "显隐指定段落文字"
If RedRange.TextRetrievalMode.IncludeHiddenText = False Then
CommandButton1.Caption = "隐藏红色段落"
Else
CommandButton1.Caption = "显示红色段落"
End If
If GreenRange.TextRetrievalMode.IncludeHiddenText = False Then
CommandButton2.Caption = "隐藏绿色段落"
Else
CommandButton2.Caption = "显示绿色段落"
End If
End Sub
Private Sub Document_Open()
UserForm1.Show (0)
End Sub
|