0

我有一种情况,我想运行一个 Visual Studio 宏,让用户在 InputBox 中输入一些内容,然后插入一个片段并将该文本包含在其中的某处。不幸的是,我不知道如何从宏代码中插入片段。好像会是这样的

DTE.ExecuteCommand("Edit.InvokeSnippetFromShortcut")

或者

DTE.ExecuteCommand("Edit.InvokeSnippetFromShortcut", "theSnippetName")

但那些不起作用。有任何想法吗?

4

2 回答 2

1

您可以使用以下代码插入片段。

DTE.ActiveDocument.Selection.Text = "snippetshortcut"
DTE.ExecuteCommand("Edit.InsertTab")

如果您使用的是 VS 2010,则需要调用 DTE.ExecuteCommand("Edit.InsertTab") 两次。

于 2011-01-18T16:21:44.327 回答
0

您需要决定应在何处选择此代码。要在当前文本选择中插入文本,您需要使用以下代码:

Dim textSelection As EnvDTE.TextSelection
textSelection = DTE.ActiveWindow.Selection          
textSelection.Insert(MyTextVarHere)
于 2009-09-07T15:22:27.147 回答