开发者

Inserting snippets from macros

In Visual Studio 2008 I had a macro which would insert a snippet and input today's date in one of the replacements. When I try to run this macro in VS 2010 it doesn't work. No matter how I try it will not insert a snippet. When I try the following command:

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

This fails with error "Error HRESULT E_FAIL has 开发者_如何学JAVAbeen returned from a call to a COM component.

I tried recording a new macro and when I pressed the keyboard shortcut for inserting a snippet (Ctrl+K, Ctrl+X) VS gave the error "The command Insert Snippet is not currently available."

Did MS remove the ability to insert snippets from macros? If so this really is a shame because macros have functionality not found in snippets and vice versa.


I finally had some time to revisit this and found a solution.

While I cannot use the "Edit.InvokeSnippetFromShortcut" command the workaround is as follows:

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

In VS 2008 you only had to have the 1 call to DTE.ExecuteCommand("Edit.InsertTab"). For whatever reason you need 2 now in order for the snippet to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜