带有 VBA 宏的 Word 2003 模板无法在 Word 2011 for MAC 中正常运行

发布于 2024-10-03 15:05:55 字数 805 浏览 3 评论 0原文

正如标题所述,我有一个带有宏的 Word 模板,该模板在 Office 2011 for MAC 的新 Word 版本中无法正常运行。

似乎无法正常工作的是以下代码:

Sub Document_New()
    myForm.Show
End Sub

Document_Open() 也是如此,

它似乎无法在 Mac 版本上运行此代码。

有谁知道为什么这在 Mac 上不起作用,或者是否有另一种方法来模拟 document_open/document_new 函数?

编辑:该文档采用 .dot 格式。我尝试将其保存到 .doc,然后 Document_open() 工作得很好,所以它似乎无法以 .dot 格式工作。并且 Document_New() 不在 .doc 中运行,因为它不是基于新的模板文件在文档上..

编辑2:似乎只在.doc 文件上使用Document_open 一次。我无法让它再次工作。太奇怪了!我工作的唯一事件是 Document_Close(),而且只有在使用 .doc 文件格式时 - 这每次都有效...

编辑 3:这变得越来越奇怪。我使用以下代码创建了一个新的 .doc 文档:

Private Sub Document_Open()
    MsgBox ("BlaBlaBla")
End Sub

只有在关闭 Word 文件并尝试再次打开它之前打开 Visual Basic 编辑器时,该代码才会运行。如果我关闭Visual Basic编辑器,然后关闭word文件,然后打开word文件;代码没有运行。

??

As the title says, I've got a word template with macros that does not run properly in the new Word version from Office 2011 for MAC.

The thing which seems to not work properly is the following code:

Sub Document_New()
    myForm.Show
End Sub

The same is with Document_Open()

It doesn't seem to run this code on the Mac version.

Does anyone know why this won't work on the Mac, or if there's another way around to emulate the document_open/document_new function?

EDIT: The document is in the .dot format. And I tried to save it to .doc, then the Document_open() worked just fine, so it seems to not be working in the .dot format.. And Document_New() is not running in .doc since its not a new templatefile based on a document..

EDIT 2: Seems like it was a once only with the Document_open on .doc files. I cant make it work again. So weird! The only event I get working, and this is only when using the .doc file format, is Document_Close() - this works everytime...

EDIT 3: This is just getting weirder. I made a new .doc document with the following code:

Private Sub Document_Open()
    MsgBox ("BlaBlaBla")
End Sub

The code only runs if the Visual Basic Editor is open BEFORE I close the word file and try to open it again. If I close the Visual Basic Editor and then the word file, and then open the word file; The code is not run.

??

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

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

发布评论

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

评论(2

溇涏 2024-10-10 15:05:55

如果 VB 编辑器处于活动状态并且当前项目未运行,则所有 VB 应用程序事件都会被抑制。这是一种有意的行为,旨在防止不需要的代码执行,因此不可调试。

我已经使用了 Workbook_Open() (在 Excel 中),并且只能从非打开的 VB 编辑器 Excel 应用程序中看到它在新打开的 Excel Xls(2010 年为 xlsm)上运行。
如果您已经打开了其他文档/xls,它将起作用,但如果 vb-editor 已启动,则不起作用。

你检查过宏是否被允许吗?您是否已生成证书并将您的应用程序设置为可信来源?

All VB application events are suppressed if you have the VB-editor active, and the current project is not running. It is an intentional behavior, to prevent unwanted code execution, hence not debuggable.

I have used Workbook_Open() (in Excel), and I can only see it working on newly open Excel Xls (xlsm on 2010), from a non-open VB-editor Excel application.
It will work if you have other doc/xls already open, but not if vb-editor is up.

Have you checked whether Macros are allowed? Do you have generated a certificate and setup your application as a trusted source?

ぽ尐不点ル 2024-10-10 15:05:55

我也有类似的问题。 MS 似乎在 Word 2011 的 Word 对象模型中删除了对 Document_New 和 Document_Open 函数的支持。请参阅 http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm

I'm having similar issues. It seems that MS removed support for the Document_New and Document_Open functions in the Word object model for Word 2011. See http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm

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