在“ThisWorkbook”下丢失 VBA 代码; (私有子WorkBook_Open())

发布于 2024-11-15 01:51:31 字数 1256 浏览 4 评论 0原文

背景的前三个元素:

  1. 我创建了一个 Excel 模板,该模板又用于创建一个“个性化模板”,其中用户名、用户评论和保存数据路径名嵌入在个性化模板中。
  2. 个性化模板用于生成每月工作簿(实际上是考勤表)
  3. 该模板是在 Vista 下运行的 Office/Excel 2007 中创建的,但(当前)目标环境是在 XP Professional 下运行 Office/Excel 2003 的公司网络。因此,这两个模板都创建为 Excel 2003 模板(在开发环境中以兼容模式运行)

到目前为止,一切顺利 - 模板在开发环境中运行良好 - “个性化”代码位于“ThisWorkbook”下的 WorkBook_Open() 例程中 - 它运行、删除自身并保存为个性化模板。两个模板在 Sheet1 代码中都有“流程宏”(这里的原理是初始模板在“ThisWorkbook”和“Sheet1”中都有宏;个性化模板仅在“Sheet1”中以及从个性化模板创建的工作簿中具有宏)根本没有宏。

在“beta 测试”中,我在 XP(文件格式)下使用 Excel2000 时遇到了问题,并且在目标计算机上,我的 WorkBook_Open 例程在主模板中被删除(而不是被删除)。在个性化模板中) - 尽管在 Excel2007/Vista 上一切正常,但

当时我觉得 Workbook_Open 的无效删除可能是一个编码错误 - 但在研究问题时,我发现了许多对“Macafee 删除 VBA 模块”的引用。我没有研究这些 - 但意识到目标机器(和环境)运行 Macafee,而我的所有计算机都运行诺顿,

我成功地重新测试了以下内容:

a) Excel 2007/Vista/诺顿
b) Excel 2007/XP Professional/诺顿
c) Excel 2000/XP Home/Norton

所以在 Excel 2003/XP Professional/Macafee 中重新测试感觉很舒服

这次我正在观察它 - 所以,再一次,看到 WorkBook_Open 例程被错误地从主模板中删除 - 不幸的是这就在 USB 存储盘(运行模板的地方)被完全破坏之前的片刻。

因此,对于问题 - 在我再次完成整个过程之前:

  1. 是否有任何客观证据表明 Macafee 删除了“自动运行”VBA 模块?
  2. 如果是,是否有任何解决方法(此模板将是在一万个企业中由三个人使用 - 所以我无法影响/修改安全策略!:( ) - 如果 Macafee 出现问题,那么我将不得不重新考虑整个事情!

First three elements of the background:

  1. I have created a Excel Template which is used, in turn, to create a 'personalised template' where user name, user comment, and save data pathnames are embedded in the personalised template.
  2. The personalised template is used to produce monthly workbooks (actually, time sheets)
  3. The template has been created in Office/Excel 2007 running under Vista but the (current) target environment is a corporate network running Office/Excel 2003 under XP Professional. Both templates are therefore created as Excel 2003 templates (which in the development environment run in compatibility mode)

So far, so good - the templates work well in the development environment - the 'personalisation' code is in a WorkBook_Open() routine under 'ThisWorkbook' - it runs, DELETES ITSELF, and saves as the personalised template. Both templates have the 'process macros' in the Sheet1 code (the principle here is that the initial template has macros in 'ThisWorkbook' and 'Sheet1'; the personalised template has macros only in 'Sheet1' and the workbooks created from the personalised template have NO MACROS AT ALL.

In 'beta testing' I had problems with Excel2000 under XP (fileformats) and on a target machine my WorkBook_Open routine was deleted in the main template (instead of in the personalised template) - even though everything worked OK on Excel2007/Vista.

I felt at the time that the invalid deleting of Workbook_Open was probably a coding error -but whilst researching the issues I found a number of references to 'Macafee deleting VBA modules'. I did not look into these - but was conscious that the target machine (and environment) run Macafee whilst all my computers run Norton.

Having recoded, I successfully retested in the following:

a) Excel 2007/Vista/Norton
b) Excel 2007/XP Professional/Norton
c) Excel 2000/XP Home/Norton

so felt comfortable to re-test in Excel 2003/XP Professional/Macafee

This time I was watching for it - so, once again, saw the WorkBook_Open routine incorrectly deleted from the main template - unfortunately this was only moments before the USB Memory Key (where the template was running from) was completely destroyed.

So to the question(s) - before I go through the whole process again:

  1. Is there any objective evidence of Macafee removing 'auto-run' VBA modules?
  2. If yes, is there any work-around (this template will be use by three people in a enterprise of ten thousand - so there is no way I will be able to influence/modify the security policies!!! :( ) - if there is a problem with Macafee then I will have to re-think the whole thing!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笙痞 2024-11-22 01:51:31

回答您的实际问题...是的,许多防病毒程序绝对认为在打开 Excel 或 Word 文档时运行的自动运行代码是不安全的,并将其删除,因为在十年前的短暂时刻,这实际上是某些蠕虫的工作方式。我不知道 MacAfee 是否特别这样做,但我肯定听说过这种情况。

To answer your actual question... YES, many antivirus programs absolutely consider autorun code that runs on opening Excel or Word docs to be unsafe, and deletes it, because for a brief moment ten years ago this was actually the way some worms worked. I don't know if MacAfee in particular does this but I've definitely heard of it happening.

绅士风度i 2024-11-22 01:51:31

以防万一其他人来到这个线程 - 我现在已经完全检查了我的模板 - 并在目标环境中重新运行它 - 并且 Workbook_Open 例程再次被删除。在目标机器上进行一些挖掘后,我发现了 Macafee 事件日志,你瞧...
事件类型:警告
事件来源:McLogEvent
活动类别:无
事件 ID:258
日期:2011年9月7日
时间:15:45:40
用户:NT AUTHORITY\SYSTEM
计算机:xxxxxxxxx
描述:
文件 F:\Timesheets\Timesheet Generator.xlt\1.OLE 包含 X97M/Generic Virus。该文件已使用扫描引擎版本 5400.1158 DAT 版本 6400.0000 成功清理。

所以有确凿的证据。
Workbook_Activate() 也会发生同样的情况

“有问题”的行似乎是

With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
        .DeleteLines 1, _
        .CountOfLines

JUst in case anyone else comes to this thread - I have now fully checked out my template - and re-run it in the target environment - and the Workbook_Open routine was again deleted. after doing some digging around on the target machine I found the Macafee event log and lo and behold...
Event Type: Warning
Event Source: McLogEvent
Event Category: None
Event ID: 258
Date: 09/07/2011
Time: 15:45:40
User: NT AUTHORITY\SYSTEM
Computer:xxxxxxxxxx
Description:
The file F:\Timesheets\Timesheet Generator.xlt\1.OLE contained X97M/Generic Virus. The file was successfully cleaned with Scan engine version 5400.1158 DAT version 6400.0000.

So there is the definitive proof.
Same thing happens with Workbook_Activate()

The 'offending' lines appear to be

With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
        .DeleteLines 1, _
        .CountOfLines
抱猫软卧 2024-11-22 01:51:31

我已成功再次访问客户端计算机 - 并添加了一个新的简单模板来证明或以其他方式解决我的问题。新的 WorkBook_Open 例程是...

Private Sub WorkBook_Open()
    MsgBox "Hello World"
    With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
        .DeleteLines 1, _
        .CountOfLines
    End With
    MsgBox "Goodbye to all that!"
End Sub

...这完全按照要求工作,即例程执行然后删除自身(即使代码已被删除,第二个消息框也会显示!

所以,这个 该例程作为 AV 保护的一部分 - 所以我不再寻找解决方法!

现在我需要做的就是弄清楚我的问题到底是什么!

测试使我的问题无效 - McAfee 不会删除

I have managed to get to the client machine again - and added a new simple template to prove or otherwise my issue. The new WorkBook_Open routine is...

Private Sub WorkBook_Open()
    MsgBox "Hello World"
    With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
        .DeleteLines 1, _
        .CountOfLines
    End With
    MsgBox "Goodbye to all that!"
End Sub

...and this works exactly as required i.e. the routine executes then deletes itself (the second msgbox displays even though the code has been deleted!

So, this test invalidates my question - McAfee is NOT deleting the routine as part of AV protection - so I am no longer looking for a workaround!

Now all I need to do is to figure out what my problem really is!

Thanks for the comments

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文