VBA WORD 2019 重新设计的评论。查找事件(如 "Comment was added" 或 "Comment has changed")以在事后自动更正评论文本



2019年,Word中的注释被重新设计。因此,评论中不再提供自动更正。我在评论中使用了自动更正功能来替换我自己的缩写。我现在使用Comments/Comment对象和AutoCorrect对象编写了一个VBA SUB。在我写完所有评论后,用我的缩写代替它们是很好的。但为了获得更直接的体验,我想将SUB与";添加了评论"-或";评论已更改"-事件,但我找不到。我能得到的最接近的是通过调用App_WindowSelectionChange((中的SUB,但选择注释气球或添加新注释并不会触发该事件。

它应该这样工作:

编辑自动校正fu1=fuggel1

选择:Word->开发工具->宏->Register_Event_Handler((

写评论,包括";fu1是最好的";

在事件变为"0"时;fuggel1是最好的";

有什么想法可以让我的SUB的电话与添加新评论或更改评论相关吗?

Rem Class EventACC
Public WithEvents App As Word.Application
Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
Rem Debug.Print ("change")
Call Auto_Correct_Comment
End Sub
Rem Module AutoCorrectComment
Dim ACC As New EventACC
Sub Register_Event_Handler()
Set ACC.App = Word.Application
End Sub
Sub Auto_Correct_Comment()
If ActiveDocument.Comments.Count >= 1 Then
For X = 1 To ActiveDocument.Comments.Count
Dim m_s_comment As String
Dim m_s_arr_comment_p() As String
m_s_comment = Trim(ActiveDocument.Comments(X).Range.Text)
m_s_arr_comment_p = Split(m_s_comment, " ")
For C = 0 To UBound(m_s_arr_comment_p)
Rem Debug.Print (m_s_arr_comment_p(C))
On Error Resume Next
Dim m_s_test As String
m_s_test = AutoCorrect.Entries(m_s_arr_comment_p(C)).Value
If Err.Number = 0 Then
Rem Debug.Print (AutoCorrect.Entries(m_s_arr_comment_p(C)).Value)
m_s_comment = Replace(m_s_comment, m_s_arr_comment_p(C), AutoCorrect.Entries(m_s_arr_comment_p(C)).Value)
Rem Debug.Print (m_s_comment)
End If
Next C
ActiveDocument.Comments(X).Range.Text = m_s_comment
Next X
End If
End Sub

我做了一些程序,现在可以在编写并确认后或稍后选择注释气球后,通过快捷键(ALT+0(更改所选注释中的缩写。请参阅下面的代码。仍然希望进行与事件相关的更改。

用法->选择:Word->开发工具->宏->AddKeyBinding((。然后,在编写并确认注释后,对注释使用快捷键(Alt+0(。

Rem Module AutoCorrectComment
Sub Auto_Correct_Comment_2()
If ActiveDocument.ActiveWindow.ActivePane.Selection.Comments.Count >= 1 Then
m_s_comment = Trim(ActiveDocument.ActiveWindow.ActivePane.Selection.Comments.Item(1).Range.Text)
m_s_comment_copy = m_s_comment
Replacement = Array(".", ",", "?", "!", ":") ' add more
For Each A In Replacement
m_s_comment_copy = Replace(m_s_comment_copy, A, " " & A & " ") ' necessary to "free" Autocorrect Element
Next A
m_s_arr_comment_p = Split(m_s_comment_copy, " ")
For C = 0 To UBound(m_s_arr_comment_p)
Rem Debug.Print (m_s_arr_comment_p(C))
On Error Resume Next
Dim m_s_test As String
m_s_test = AutoCorrect.Entries(m_s_arr_comment_p(C)).Value
If Err.Number = 0 Then
Debug.Print (m_s_arr_comment_p(C))
Rem Debug.Print (AutoCorrect.Entries(m_s_arr_comment_p(C)).Value)
m_s_comment = Replace(m_s_comment, m_s_arr_comment_p(C), AutoCorrect.Entries(m_s_arr_comment_p(C)).Value)
Rem Debug.Print (m_s_comment)
End If
Next C
ActiveDocument.ActiveWindow.ActivePane.Selection.Comments.Item(1).Range.Text = m_s_comment
End If
End Sub

Sub AddKeyBinding()
With Application

.CustomizationContext = ActiveDocument.AttachedTemplate
' \ Add keybinding to Active.Document Shorcut: Alt+0
.KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKey0), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="Auto_Correct_Comment_2"
End With
End Sub

相关内容

最新更新