设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 4172|回复: 4

Word VBA 如何让WORD不记录历史信息

[复制链接]
发表于 2007-4-13 00:19:00 | 显示全部楼层 |阅读模式
在VBA编程时,VBA代码执行的操作都会出现在WORD的历史记录里,我不想让用户知道我的操作过程。

WORD提供有清除所有的历史信息的方法,而我只想清除指定的历史信息。

有那位高人赐教一二。
发表于 2007-4-19 01:31:00 | 显示全部楼层
惭愧!

不知道有何方法。
发表于 2007-4-22 00:41:00 | 显示全部楼层
恐怕没有
发表于 2007-4-30 20:03:00 | 显示全部楼层
我知道有这个功能,但现在记不到了。

如在调用模板建立一个新文档,又不希望用户看到模板时就需要此功能。

[此贴子已经被作者于2007-4-30 14:55:04编辑过]

发表于 2007-4-30 23:06:00 | 显示全部楼层
Dim docnormal As Document
Private Sub Chk联合发文_Click()
  If Txt成文机关 = "—无—" Or Txt联合单位 = "—无—" Then
    Chk联合发文 = False
  End If
End Sub
Private Sub Chk签发人_Change()
  If Txt签发人 = "—无—" Then
    Chk签发人 = False
  End If
End Sub
Private Sub CmdEND_Click()
  ActiveDocument.Close wdDonoSaveChanges
  Unload Me
End Sub
Private Sub Cmd选择_Click()
  Dim a As Dialog
  On Error GoTo e:
  Set a = Dialogs(wdDialogCopyFile)
  a.directory = Txt保存位置
  a.Display
  Txt保存位置 = Mid(a.directory, 2, Len(a.directory) - 2)
  Exit Sub
e:
  a.directory = Options.DefaultFilePath(wdDocumentsPath)
  Resume Next
End Sub
Private Sub CmdOK_Click()
  Dim i As Integer, widthpage
  docnormal.Variables("文件编号") = Txt文件编号    '更改预先定义在模板中变量的值
  docnormal.Variables("签发人") = Txt签发人
  docnormal.Variables("代字") = Txt代字
  docnormal.Variables("年度") = Txt年度
  docnormal.Variables("成文机关") = Txt成文机关
  docnormal.Variables("联合单位") = Txt联合单位
  docnormal.Variables("保存位置") = Txt保存位置
  Documents(docnormal).SaveAs , AddToRecentFiles:=False         '防止显示在最近文档列表中
  Documents(docnormal).Close
  Options.PrintDrawingObjects = False
  Selection.TypeText Txt年度
  Selection.MoveRight Unit:=wdCharacter, Count:=1
  Selection.TypeText Txt文件编号
  If Chk签发人 = True Then
    Selection.EndKey Unit:=wdLine
    With Selection.Font
      .Name = "仿宋_GB2312"
      .Size = 16
      .Bold = True
      Selection.TypeText "签发人"
      .Name = "楷体_GB2312"
      Selection.TypeText ":" + Txt签发人
    End With
  End If
  Selection.MoveDown Unit:=wdLine, Count:=3
  Selection.ParagraphFormat.FirstLineIndent = 0
  With Selection.Font
    .Name = "方正小标宋简体"
    .Size = 19
    .DisableCharacterSpaceGrid = True
  End With
  With ActiveDocument.PageSetup
    widthpage = .PageWidth - .LeftMargin - .RightMargin
  End With
  If Chk联合发文 = True Then
    With ActiveDocument.PageSetup
      widthpage = .PageWidth - .LeftMargin - .RightMargin
    End With
    If Len(Txt联合单位) < Len(Txt成文机关) Then
      Selection.ParagraphFormat.LeftIndent = (widthpage - Len(Txt成文机关) * Selection.Font.Size - 5) / 2
    Else
      Selection.ParagraphFormat.LeftIndent = (widthpage - Len(Txt联合单位) * Selection.Font.Size - 5) / 2
    End If
    Selection.ParagraphFormat.RightIndent = Selection.ParagraphFormat.LeftIndent
    Selection.ParagraphFormat.Alignment = wdAlignParagraphDistribute
    Selection.TypeText Text:=Txt成文机关 + Chr(11) + Txt联合单位
  Else
    Selection.TypeText Text:=Txt成文机关
  End If
  Selection.MoveDown Unit:=wdLine, Count:=1
  If Chk保存 = True Then
    ActiveDocument.SaveAs Txt保存位置 + Txt文件名 + ".doc"
  End If
  For i = 1 To CommandBars("formatting").Controls.Count     '格式工具栏
    CommandBars("formatting").Controls(i).Enabled = True   '按钮有效
  Next i
  For i = 3 To CommandBars("Standard").Controls.Count     '常用工具栏
    CommandBars("Standard").Controls(i).Enabled = True   '按钮无效
  Next i
  Unload Me
End Sub
Private Sub Txt代字_AfterUpdate()
  If Txt代字 = "" Then Txt代字 = "公文"
  Txt代字 = Trim(Txt代字)
End Sub
Private Sub Txt联合单位_AfterUpdate()
  If Txt联合单位 = "" And Txt联合单位 <> "—无—" Then
    Txt联合单位 = "—无—"
    Chk联合发文 = False
  End If
  Txt联合单位 = Trim(Txt联合单位)
End Sub
Private Sub Txt成文机关_AfterUpdate()
  If Txt成文机关 = "" Or Txt成文机关 = "—无—" Then
    Txt成文机关 = "—无—"
    Txt联合单位.Enabled = False
    Chk联合发文 = False
  Else
    Txt联合单位.Enabled = True
  End If
  Txt成文机关 = Trim(Txt成文机关)
End Sub
Private Sub Txt签发人_AfterUpdate()
  If Txt签发人 = "" And Txt签发人 <> "—无—" Then
    Txt签发人 = "—无—"
    Chk签发人 = False
  E
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-3-29 21:32 , Processed in 0.088297 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表