dte.ExecuteCommand“Edit.Find”找不到引号?

时间:2017-11-29 23:42:31

标签: vba visual-studio

MSVS_versions = Array _
( _
    "VisualStudio.DTE.7", _
    "VisualStudio.DTE.7.1", _
    "VisualStudio.DTE.8.0", _
    "VisualStudio.DTE.9.0", _
    "VisualStudio.DTE.10.0", _
    "VisualStudio.DTE.11.0", _
    "VisualStudio.DTE.12.0", _
    "VisualStudio.DTE.14.0" _
)

For each version in MSVS_versions
    Err.Clear
    Set dte = getObject(,version)
    If Err.Number = 0 Then
        Exit For
    End If
Next

If Err.Number <> 0 Then
    Set dte = WScript.CreateObject("VisualStudio.DTE")
    Err.Clear
End If


dte.MainWindow.Activate
dte.MainWindow.Visible = True
dte.UserControl = True

dte.ItemOperations.OpenFile filename
if keyword is not nothing then
    dte.ExecuteCommand "Edit.Find", """"
end if

我有这个vba代码。我对第二行感兴趣。我想在当前的docurnet中找到一个引号。当我运行代码时,Visual Studio告诉我

---------------------------
Microsoft Visual Studio
---------------------------
The search pattern is invalid.
---------------------------
OK   
---------------------------

如何搜索引号?

1 个答案:

答案 0 :(得分:0)

dte.ExecuteCommand接受的参数是我们可以在Visual Studio的命令窗口中输入的内容。

enter image description here

命令窗口提供与找到的OP相同的错误。

https://docs.microsoft.com/en-us/visualstudio/ide/reference/command-window#escape-characters表示转义字符为 ^ ,因此您必须使用dte.ExecuteCommand "Edit.Find", "^"""才能找到"

截至Edit.Find的所有参数,请参阅https://docs.microsoft.com/en-us/visualstudio/ide/reference/find-command