Word中表格的事件更改 [英] Event change of table in Word

查看:134
本文介绍了Word中表格的事件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Document_Change(ByVal Target As Range)
Set table = ActiveDocument.Tables(1)
If Not Intersect(table, Target) Is Nothing Then
Target.AutoFormat ApplyColor: Red
End If
End Sub

我有以下代码,但在VBA Word中似乎不起作用. 有人可以帮我吗?

I have the following code, but it does not seem to work in VBA Word. Can anyone help me out?

推荐答案

我想您是从Excel VBA复制代码并尝试重新构建它. Excel和Word VBA之间有一些区别.

I suppose that you copied the code from Excel VBA and tried to rebuild it a bit. There are a few differences between Excel and Word VBA.

  1. Intersect在Word VBA中不存在.
  2. Word中的
  3. DocumentChange事件的工作原理与您期望的不同-创建新文档,打开现有文档或将另一个文档设为活动文档时,将发生此事件. ( https://msdn.microsoft.com/en-us/library /office/ff822189.aspx )
  1. Intersect does not exist in Word VBA.
  2. DocumentChange event in Word works differently from what you would expect - It occurs when a new document is created, when an existing document is opened, or when another document is made the active document. (https://msdn.microsoft.com/en-us/library/office/ff822189.aspx)

如果要以红色进行更改,则可以执行以下操作:

If you want to make changes in red, you may do the following:

  1. 用静态字符串记录整个文档.
  2. 发生更改时-再次记录一个新字符串.
  3. 比较字符串并为差异着色.

但是,这有点困难,因为单词没有我们期望的Change事件(例如,在Excel中).因此,您应该自动运行几次VBA代码.

However, this is a bit tough, as far as word does not have Changeevent as we are expecting it (e.g. as in Excel). Thus, you should run the VBA code a few times automatically.

这篇关于Word中表格的事件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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