Visual Basic Development Bookmark and Share   
 Home > Visual Basic IDE > How to call the VB Code Formatter from macro
 

How to call the VB Code Formatter from macro

Is it possible to call the VB code formatter from within a macro?

I wrote a macro that automatically adds a call to the logger in side an function or sub when it is created. But when I change the TextEditor.Enter command to my macro, nocode formating takes place.

Is there a way to call the original command Edit.BreakLine(Enter(TextEditor)) ??

Thank you.

Harry

  • Moved byDmitry GoncharenkoMSFTFriday, November 13, 2009 5:12 PMto get better support (From:Visual Studio Extensibility)
  •  
Harry14  Thursday, November 12, 2009 10:21 AM

Hello Harry,


You can callDTE.Document.Selection.NewLine() to insert anew lineat the location of the cursor. If you want toformat the codes in the active document, you can call ExecuteCommand function. Codes look like,
------------------------------------------------------------------------

DTE.ActiveDocument.Selection.NewLine()

DTE.ExecuteCommand(

"Edit.FormatDocument")
------------------------------------------------------------------------

"Edit.FormatDocument")
------------------------------------------------------------------------


Hope this helps! Have a nice day.

Ji Zhou

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byHarry14 Monday, November 16, 2009 7:53 AM
  •  
Ji.Zhou  Monday, November 16, 2009 6:45 AM

Hello Harry,


You can callDTE.Document.Selection.NewLine() to insert anew lineat the location of the cursor. If you want toformat the codes in the active document, you can call ExecuteCommand function. Codes look like,
------------------------------------------------------------------------

DTE.ActiveDocument.Selection.NewLine()

DTE.ExecuteCommand(

"Edit.FormatDocument")
------------------------------------------------------------------------

"Edit.FormatDocument")
------------------------------------------------------------------------


Hope this helps! Have a nice day.

Ji Zhou

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byHarry14 Monday, November 16, 2009 7:53 AM
  •  
Ji.Zhou  Monday, November 16, 2009 6:45 AM
Thank you. That worked fine.
Harry14  Monday, November 16, 2009 7:53 AM

You can use google to search for other answers

Custom Search

More Threads

• The ToolStripMenuItem is disappeared, please help me!
• adding combobox for one cell into the datagrid
• VS2005 - Localization problems
• clearing recent projects list
• Solution Explorer Window Moving
• VisualStudio insists on using FireFox to run a WebService
• IDE annoyances
• text to appear in a certian order
• System:InvalidOperationException
• AutoCorrect inellisenseoptions