Word SelectionChange 事件

Word SelectionChange event

提问人:Yiftach Cohen 提问时间:11/5/2023 最后编辑:braXYiftach Cohen 更新时间:11/5/2023 访问量:44

问:

我在 MS Word 中使用 VBA(使用 Developer => Visual Basic 选项)

我尝试捕获当我滚动到文档中的不同页面(无论是通过鼠标还是键盘)时触发的事件 我尝试使用不同的事件名称(根据我在互联网上找到的内容),但没有任何发现

Private Sub ThisDocument_SelectionChange(ByVal Sel As Selection)
    ' Check if the user is scrolling (i.e., changing the selection)
    ' and display a message box.
    
    MsgBox "You are scrolling the document."
    
End Sub
Private Sub ThisDocument_WindowSelectionChange(ByVal Sel As Selection)
    ' Check if the user is scrolling (i.e., changing the selection)
    ' and display a message box.
    
    MsgBox "You are scrolling the document."
    
End Sub
Private Sub Document_SelectionChange(ByVal Sel As Selection)
    ' Check if the user is scrolling (i.e., changing the selection)
    ' and display a message box.
    
    MsgBox "You are scrolling the document."
    
End Sub

Private Sub Document_WindowSelectionChange(ByVal Sel As Selection)
    ' Check if the user is scrolling (i.e., changing the selection)
    ' and display a message box.
    MsgBox "You are scrolling the document."
    
End Sub

我在这里错过了什么?

谢谢

VBA MS-Word

评论

0赞 Yiftach Cohen 11/5/2023
嗨,我尝试了一个滚动页面的宏,它给了我以下代码: 但这是一个方法,而不是一个事件,我需要一个捕获这些操作的事件,最好是在页面因任何原因更改时Sub Macro1() ' ' Macro1 Macro ' ' Selection.MoveDown Unit:=wdScreen, Count:=3 Selection.MoveUp Unit:=wdScreen, Count:=2 End Sub
0赞 braX 11/5/2023
没有这样的活动。也许您可以解释一下当用户滚动时您到底想做什么?
0赞 Yiftach Cohen 11/5/2023
我想更改文档中不同页面的文档背景,因此如果我在第 1-10 页,背景将是蓝色,而当我在第 11-20 页时,背景将是 yelllow 等。我不能为每一页做不同的背景,只能为整个文档做不同的背景,所以我想欺骗文档根据我当前正在查看的页面更改背景颜色
0赞 braX 11/5/2023
您也无法单独控制每个页面的背景颜色。听起来您需要一个例程来单独打印每一页,在每页打印之间更改整个文档的背景颜色。
1赞 braX 11/5/2023
也许你可以找到一些东西来帮助你走这条路:learn.microsoft.com/en-us/office/vba/word/concepts/......

答: 暂无答案