|
楼主 |
发表于 2023-5-20 20:35
|
显示全部楼层
本帖最后由 OKJSJSF 于 2023-5-21 21:08 编辑
基本定稿
Sub 窗体域打印设置()
Dim i As Byte, ff As FormField
With ActiveDocument
If .ProtectionType <> wdNoProtection Then .Unprotect
On Error Resume Next '单击关闭、取消按钮或录入超范围数字时不出错,返回对话框重录
Do
i = InputBox("下框中可录数字1234与对应的打印效果:" & vbCr & "1 加灰色底纹 2 加下划线、字形加粗" & vbCr & "3 取消前二项设置 4 其它设置", "参数设置", 1)
If i = 1 Or i = 2 Or i = 3 Or i = 4 Then Exit Do '如果录入小数,VBA会自动取整,有点不明不白程序就执行了,所以变量类型可以改为占用系统资源更大的小数
Loop
Select Case i
Case 1
For Each ff In .FormFields
With ff.Range
.Shading.Texture = wdTexture15Percent
.Font.Underline = wdUnderlineNone
.Font.Bold = False
End With
Next
Case 2
For Each ff In .FormFields
With ff.Range
.Shading.Texture = wdTextureNone
.Font.Underline = wdUnderlineSingle
.Font.Bold = True
End With
Next
Case 3
For Each ff In .FormFields
With ff.Range
.Shading.Texture = wdTextureNone '无底纹
.Font.Underline = wdUnderlineNone '无下划线
.Font.Bold = False '字形常规
End With
' ff.Range.Select
' Selection.ClearFormatting '删除字符格式与段落格式相当于恢复默认正文样式,不行
' Selection.ClearCharacterDirectFormatting '删除字符格式不会恢复默认字号
Next
Case Else
' .DeleteAllEditableRanges wdEditorEveryone
Application.ScreenUpdating = False
For Each ff In .FormFields
ff.Range.Select '当窗体域个数稍多时,一旦采用对象的.select方法,数据刷新明显可见,关闭屏幕刷新后效果稍好点
Selection.Range.Editors.Add wdEditorEveryone '逐个增加用户可编辑区域
Next
Application.ScreenUpdating = True
.SelectAllEditableRanges wdEditorEveryone
.DeleteAllEditableRanges wdEditorEveryone
.Application.Dialogs(wdDialogFormatFont).Show '打开字体设置对话框
.FormFields(1).Select '我习惯于执行完毕后定位第一个窗休而不是最后一个。奇怪的是用代码sendkeys "^{home}",true不能返回文档开头,手工快捷键却可以
End Select
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
MsgBox "执行完毕。"
End With
End Sub
|
|