Visual Studio Tools for Office 破坏了 VB6

发布于 2024-10-22 04:56:25 字数 1207 浏览 1 评论 0原文

更新3:

当我保存 vb6 时会发生这种情况 脚本,结束词,开始词,然后 像平常一样运行模板 运行模板,即 strTemplate 变成Normal.doc。然后一旦我 返回到原始模板 尚未通过 vsto 保存,即 回到 Letter.doc 中 变量 strTemplate...

更新2:

在我的启动脚本中,我有一行如下:

strTemplate = ActiveDocument.AttachedTemplate

在名为Letter.dot的原始模板中,strTemplate = Letter.dot。

但由于某种原因,在基于原始 Letter.dot 模板的新 vsto 模板中,上面的同一行变成了 Normal.dot,这导致了问题,即使新模板仍然命名为 Letter.dot。

我尝试手动编码

strAttTemplate = "Letter.dot"

,脚本进入下一阶段,但随后它开始抱怨其他事情。

所以我的问题是,原始模板有 strTemplate = Letter.dot,但是为什么在通过 vsto 运行模板后会变成 strTemplate = Normal.dot?

更新1:

对两个版本的模板(即原始非 vsto 模板和新 vsto 模板)进行调试后,我发现原始模板没有任何文档属性,但是vsto 模板有 2 个文档属性。但这似乎不是问题。

看来该问题与 vsto 模板附加了 normal.dot 有关,而原始的非 vsto 模板没有附加 normal.dot。

是否可以从新模板中删除附加的normal.dot?

原始问题

我正在使用 Visual Studio 2008 创建 Word 2003 模板项目。我选择“使用现有模板”选项,该选项在后台已有一些 vb6 宏脚本。由于某种原因,当我保存 Visual Studio 项目时,vb6 脚本停止工作。

当模板在word中打开时,旧的vb6脚本会立即运行,但是当我只是在vs2008中使用模板而不添加额外的功能并保存项目并构建项目时,当我尝试在word中打开模板时,旧的启动脚本不起作用。

为什么会发生这种情况?

UPDATE 3:

This happens when I have saved the vb6
script, close word, start word, then
run the template as you would normally
run a template, i.e. strTemplate
becomes Normal.doc. Then as soon as I
go back to the original template which
has not been saved through vsto, that
goes back to having Letter.doc in the
variable strTemplate...

UPDATE 2:

In my startup script, I have a line as follows:

strTemplate = ActiveDocument.AttachedTemplate

In the original template which is named Letter.dot, strTemplate = Letter.dot.

But for some reason, in the new vsto template which was based on the original Letter.dot template, the same line above becomes Normal.dot, which is causing problems, even thought the new template is still named Letter.dot.

I tried to manually code in

strAttTemplate = "Letter.dot"

and the script gets to the next stage, but then it starts complaining about something else.

So my question is, the original template has strTemplate = Letter.dot, but why does this change to strTemplate = Normal.dot after running the template through vsto?

UPDATE 1:

After running through a debug for both versions of the template, i.e. the original non vsto template, and the new vsto template, I have found out that the original does not have any document properties, but the vsto template has 2 document properties. But that does not seem to be a problem.

It seems that the problem has something to do with the vsto template has normal.dot attached to it, whereas the original non vsto template does not have normal.dot attached to it.

Is it possible to remove attached normal.dot from the new template?

ORIGINAL QUESTION:

I am using Visual Studio 2008 to create a Word 2003 Template project. I select the "use existing template" option which already has some vb6 macro scripting in the background. For some reason, when I save the Visual Studio project, the vb6 scripting stops working.

the old vb6 script runs straight away when the template opens in word, but when i simply use the template in vs2008 without adding extra functionality and save the project and build the project, when i try to open the template in word, the old startup script does not work.

Why is this happening?

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

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

发布评论

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

评论(2

无妨# 2024-10-29 04:56:25

可能的情况是,您的 Word 2003 .dot VBA 中有一个名为 AutoExec 的例程。当部署为 VSTO 模板时,此函数不会执行,因为它不是 Word 运行 AutoExec 所需的加载项类型(它需要 STARTUP 文件夹中的 .wll 文件或 .dot 文件)。 VSTO 的解决方法是使用 AutoOpen,当模板作为 VSTO 外接程序打开时,它将执行该子例程中的代码。

您可以在 VBA 中尝试这三种方法(在 Word 中,按 Alt + F11 进入 Visual Basic 编辑器):

Sub AutoNew()
    MsgBox "AutoNew runs when creating a document from a template"
End Sub
Sub AutoOpen()
    MsgBox "AutoOpen runs when opening a template as a document"
End Sub
Sub AutoExec()
    MsgBox "AutoExec runs when loading an add-in (a global template)"
End Sub

另一种情况是您没有安全设置在开发计算机的 Word 安全设置中设置为“低”。


关于更新#2,当您在调试模式下运行 VSTO(F5 而不是编译并运行 Ctrl + F5)时,通常会发生这种情况。你能确认一下你是如何运行它的吗?如果不是其中之一,那么当您将其部署到测试机器时,它仍然是normal.dot吗?

最后,如果您可以发布完整的启动脚本,这将有助于确定问题的真正所在。

The likely scenario is that you have a routine called AutoExec in your Word 2003 .dot VBA. This will not execute when deployed as a VSTO template because it's not the type of add-in Word expects in order to run AutoExec (it expects either .wll files or .dot files in your STARTUP folder). The way around this for VSTO is to use AutoOpen instead which will execute the code in that sub routine when the template is opened as a VSTO add-in.

You can try these three in VBA (in Word, press Alt + F11 to get to the Visual Basic Editor):

Sub AutoNew()
    MsgBox "AutoNew runs when creating a document from a template"
End Sub
Sub AutoOpen()
    MsgBox "AutoOpen runs when opening a template as a document"
End Sub
Sub AutoExec()
    MsgBox "AutoExec runs when loading an add-in (a global template)"
End Sub

The other scenario is you don't have your security settings set to "Low" on your development machine's Word security settings.


Regarding your update #2, this usually happens when you run VSTO in debug mode (F5 instead of compiling and running it Ctrl + F5). Can you confirm how you are running it? If it is neither one of those, is it still normal.dot when you deploy it to a test machine?

Finally, if you could post your full startup script, that would be helpful in determining where the issue may truly lie.

三生池水覆流年 2024-10-29 04:56:25

2003 模板是否有可能创建 DOCX 或 DOTX 文件,而不是 DOCM 或 DOTM 文件?在 2003 及更高版本中,宏代码在 DOCX 或 DOTX 文件中时不会运行。

Is it possible the 2003 template is creating a DOCX or a DOTX file, and NOT a DOCM or DOTM file? With 2003 and later, Macro code won't run when it's in a DOCX or DOTX file.

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