总之,我无法使焦点移到目标上Selection.Find.Execute (findText)
在word文档中,我有一个按钮,可以将要做的事情列表的顶部项目移到日志部分。下面是移动项目的代码;bMoveToLog。把注意力放在要做的事情上。现在我想要一个按钮,将焦点向下移动到日志后面的标题& MYLOG"所以我可以做我的时间表。
有一个我尝试过的选项列表。
如何将焦点移动到select . find . execute的目标上?
Private Sub bMoveToLog_Click()
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute
findText = "TODO"
Selection.Find.Execute (findText)
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdMove
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Cut
findText = "MYLOG"
Selection.Find.Execute (findText)
Selection.MoveDown Unit:=wdParagraph, Count:=2, Extend:=wdMove
Selection.InsertDateTime
Selection.InsertBefore (" ")
Selection.Paste
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute
End Sub
Private Sub bViewLog_Click()
findText = "MYLOG"
myRange = Selection.Find.Execute(findText)
myRange.Select '*** This doesn't work - how do I set focus
End Sub
选项尝试
'various attempts
'Selection.MoveDown Unit:=wdParagraph, Count:=2
'Selection.GoToEditableRange wdEditorCurrent
'myRange.Select
'Selection.GoTo what:=wdGoToPage, which:=wdGoToAbsolute
'Selection.MoveDown Unit:=wdParagraph, Count:=2, Extend:=wdMove
'ActiveSheet.Range("D5").Select
'This works but doesn't use search
'Selection.GoTo What:=wdGoToPage, Count:=6
调试显示ViewLog例程中的搜索没有执行它的工作。搜索没有执行。这就是为什么焦点没有落在预期的地方。通过添加一个选择修复了这个问题。在搜索前的Goto语句将焦点放在页面上。
新的View-Log例程是;
Private Sub bViewLog_Click()
'Selection.GoTo is needed to put focus on a page
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute
findText = "MYLOG"
Selection.Find.Execute (findText)
Selection.MoveDown Unit:=wdParagraph, Count:=2, Extend:=wdMove
End Sub