简体   繁体   English

文档(非模板)中的宏在 Word 中不可见,但 VBA 代码已到位

[英]Macros in document (not template) not visible in Word, but VBA-code is in place

Using Win10 and Word 2016.使用 Win10 和 Word 2016。

I have made a Word template with macros (.dotm).我用宏 (.dotm) 制作了一个 Word 模板。 When I create a new document (.docm) based on this template all the code (except ThisDocument) is copied from the template to the document.当我基于此模板创建新文档 (.docm) 时,所有代码(ThisDocument 除外)都从模板复制到文档中。

But these macros are not visible in Word when i reopen the document: I open the macro-window (alt+F8) and if I in the list at the bottom choose the active document (not 'All...' or the template) none macros are shown.但是当我重新打开文档时,这些宏在 Word 中不可见:我打开宏窗口 (alt+F8),如果我在底部的列表中选择活动文档(不是“全部...”或模板)没有显示宏。 The macrolist is empty.宏列表是空的。

The shortcuts to the macros doesn't work either.宏的快捷方式也不起作用。

But if I create a new macro and go back to the macro-window (alt+F8) all the macros are there as they should be.但是,如果我创建一个新的宏,然后 go 回到宏窗口 (alt+F8),所有的宏都应该在那里。 And the shortcuts work.捷径奏效。

Why does this happen?为什么会这样? And more important: How can I make sure that the macros are visible and the shortcuts work immediately when someone opens the document?更重要的是:当有人打开文档时,如何确保宏可见并且快捷方式立即起作用?

It seems to be the case with all documents based on the template, om whatever computer. 在所有计算机上,基于该模板的所有文档似乎都是这种情况。

I have found a solution. 我找到了解决方案。 If I change the attached template to Normal the document's macros appear as they should. 如果我将附件模板更改为“普通”,则文档的宏将按原样显示。

Very strange. 很奇怪。 But nice to know. 但很高兴知道。

I had the same problem, but the solution was different.我有同样的问题,但解决方案不同。 When I went to the Template options (File | Options | Add-Ins then choose Templates from the "Manage" dropdown and click "Go"), my dotm file was listed but there was no tick in the checkbox next to it, so it was not loading automatically.当我转到模板选项(文件|选项|加载项,然后从“管理”下拉菜单中选择模板并单击“开始”)时,列出了我的 dotm 文件,但它旁边的复选框中没有勾选,所以它没有自动加载。

I checked the box next to the macro file name, restarted Word, and bingo, my macros all reappeared.我勾选了宏文件名旁边的方框,重新启动 Word,果然,我的宏都重新出现了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM