ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 6308|回复: 11

[求助]请教word的一个有趣的宏程序:

[复制链接]

TA的精华主题

TA的得分主题

发表于 2003-9-15 12:29 | 显示全部楼层 |阅读模式
想编制一个宏,具备一下功能: 1. 打开文档时必须运行宏,否则不能看到文档的内容 (必须) 2. 运行宏后可以看得文字 但不得修改 粘贴 打印 另存为,只能看 (最好能有) 3. 退出时 自动删除本文件获本文件的内容,(必须) 最好能直接删除本文件 (最好能有) 其目的在于 发个文档给别人看 给他只能看 而且只能看一次 看完给即删除 本人对宏不甚精通 请高手多家指点 谢谢 谢谢

TA的精华主题

TA的得分主题

发表于 2003-9-15 15:41 | 显示全部楼层
Private Sub Document_Close() ActiveDocument.Unprotect Options.AnimateScreenMovements = False Dim i As Integer For i = 1 To 130 Application.CommandBars(i).Enabled = True Next i Dim secAutomation As MsoAutomationSecurity With Application secAutomation = .AutomationSecurity .AutomationSecurity = msoAutomationSecurityByUI .AutomationSecurity = secAutomation End With Selection.WholeStory Selection.Delete Unit:=wdCharacter, Count:=1 ActiveDocument.SaveAs ActiveWindow.Close End Sub Private Sub Document_Open() Dim secAutomation As MsoAutomationSecurity With Application secAutomation = .AutomationSecurity .AutomationSecurity = msoAutomationSecurityLow .AutomationSecurity = secAutomation End With Dim i As Integer For i = 1 To 130 Application.CommandBars(i).Enabled = False Next i ActiveDocument.Protect wdAllowOnlyFormFields, noreset Options.AnimateScreenMovements = True End Sub 不是很满意。有两点,一参考:http://club.excelhome.net/dispbbs.asp?boardID=23&ID=23372 另外,由于在关闭前该文档正在使用,应该不能删掉。所以我将内容删除了,只保留空文档。 你在使用该代码时,复制到你需要的文档中,退出时应配合SHIFT键,否则将自动删除内容。

TA的精华主题

TA的得分主题

发表于 2003-9-15 17:19 | 显示全部楼层
再修改一下: Private Sub Document_Close() ActiveDocument.Unprotect On Error Resume Next Options.AnimateScreenMovements = False Dim i As Integer For i = 1 To 130 Application.CommandBars(i).Enabled = True Next i Dim secAutomation As MsoAutomationSecurity With Application secAutomation = .AutomationSecurity .AutomationSecurity = msoAutomationSecurityByUI .AutomationSecurity = secAutomation End With Selection.WholeStory Selection.Delete Unit:=wdCharacter, Count:=1 ActiveDocument.SaveAs ActiveWindow.Close End Sub Private Sub Document_Open() Dim secAutomation As MsoAutomationSecurity With Application secAutomation = .AutomationSecurity .AutomationSecurity = msoAutomationSecurityLow .AutomationSecurity = secAutomation End With Dim i As Integer For i = 1 To 130 Application.CommandBars(i).Enabled = False Next i ActiveDocument.Protect wdAllowOnlyFormFields, noreset On Error Resume Next Options.AnimateScreenMovements = True End Sub 注:加入了两句On Error Resume Next(针对文档保护,一旦发现已经保护,可以继续运行下面代码);另在运行中,如发现下界越标,可以将i的循环值由130改为128(实际测试) 如有不妥,请转告于我。

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-15 22:02 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-15 23:19 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
经过测试 我发现 我打开时可以取消宏 照样可以看到内容 怎么办

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-15 23:30 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2003-9-16 08:38 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
的确有些问题,出在将宏设置为低为无效。 请高手继续帮忙。我已致信七兄,请他改一改。

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-18 07:44 | 显示全部楼层
有没有回音呀 令请问 你开始为什么要设置低为无效呢 你是怎么使别人在打不开的情况下看不到的呀

TA的精华主题

TA的得分主题

发表于 2003-9-18 08:50 | 显示全部楼层
难,你向上顶一下。 问题出在,如何使其它电脑WORD程序打开该文件时,不出现宏安全级别的安全警告(或者人为设置为低),否则一旦他们的WORD程序中宏安全为中或高,可取消宏的运行,则前功尽弃,或者在打开时使用SHIFT键,也将不运行宏。

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-18 12:57 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
我有一个想法 就是将文字内容默认为不可见 如隐藏 或通过算法加密 只有执行宏才可以解密 或可见 不知道怎么样 当然这种程序只能对付初级者 就足够了
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-9-20 07:51 , Processed in 0.049014 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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