在 MS Word 中对应用程序对象使用事件 [英] Using Events with the Application Object in MS Word

查看:45
本文介绍了在 MS Word 中对应用程序对象使用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Word 女士不想加载我的加载项.我想在打印事件上调用用户表单.这是我的代码:

Ms Word does not want to load my add-in. I want to call a userform on print event. Here is my code:

在模块 1

Option Explicit

Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
'Debug.Print Now & " " & "App_DocumentBeforePrint: " & Wb.FullName
Userform1.Show
End Sub

Sub InitializeApp()
Dim X As New EventClassModule
Set X.App = Word.Application
End Sub

在文档模块中

Private Sub Document_Open()
Call InitializeApp
End Sub

在 EventClassModule 中

in EventClassModule

Public WithEvents App As Word.Application

在 Userform1 模式下

in Userform1 Mode

Option Explicit

Private Sub UserForm1_Initialize()
End Sub

我使用这 2 个链接来帮助我编写此代码

I used this 2 links to help me write this code

1) https://msdn.microsoft.com/en-us/library/bb221264%28v=office.12%29.aspx

2) https://msdn.microsoft.com/en-us/library/gg597509%28v=office.14%29.aspx

谁能告诉我为什么我的代码不起作用?

Can anyone tell why my code does not work?

推荐答案

如您显示的第一个链接中所述,过程 App_DocumentBeforePrint 需要在 CLASS 模块(EventClassModule,在您的解释中),不在模块 1 中.

As explained in the first link you show, the procedure App_DocumentBeforePrint needs to be in the CLASS module (EventClassModule, in your explanation), not in Module 1.

除此之外,不清楚您所说的我的加载项"是什么意思.通常,当使用这个术语时,我会想到一个模板(或 COM 加载项),它作为加载项加载.我担心 Document_Open 是否真的被触发以初始化您的事件.这个事件,在 ThisDocument 模块中(实际上,它是一个类)只会在包含此代码的文档被打开时触发...

Other than that, it's not clear what you mean by "my add-in". Usually, I'd think of a template (or COM add-in) when this term is used that's being loaded as an add-in. I'm concerned whether Document_Open is actually being triggered to initialize your events. This event, in the ThisDocument module (in reality, it's a class) will only fire when the document containing this code is opened...

这篇关于在 MS Word 中对应用程序对象使用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆