English 中文(简体)
Word VBA范围。查找对象工作不正常
原标题:Word VBA Range.Find object works incorrectly

我发现了一件有趣的事情:

在word 2010中,选择一些文本,然后运行以下VBA代码:

public Sub Test()
    With Selection.Range.Find
        MsgBox .Execute(Selection.Range.text) 
        MsgBox .Found
    End With
End Sub

两个消息框都显示“False”,但都应为“True”。为什么?

问题回答

非常有趣

Word 2007也表现出同样的行为。

The curious thing is that this not only when you are searching from VBA: If you select some text in the doc and press "find", the find dialog displays as default the selected text as objective.
By pressing "Find Next >" Word displays an error message "Word has reached the end of the document ... etc".

如果修改文本以搜索删除最后一个字符,则不会发生这种情况。VBA与之一致:以下代码有效!

Sub tt()
    With Selection.Range.Find    
       MsgBox .Execute(Mid(Selection.Range.Text,1,Len(Selection.Range.Text)-1))  
       MsgBox .Found  
    End With  
End Sub

未解决。。。但是被证明与GUI一致。

啊!





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签