Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:20:25+00:00 2026-06-09T17:20:25+00:00

If I was to have: /// <summary> /// My summary /// </summary> /// <param

  • 0

If I was to have:

/// <summary>
/// My summary
/// </summary>
/// <param name='args'></param>

on the clipboard pasted it on top of the method static void Main(string[] args), it will look like:

class Program
{
    /// <summary>
    /// This is my summary
    /// </summary>
    /// <param name='args'></param>
    static void Main(string[] args)
    { 
    }
}

Note: The text I had on the clipboard had no indentation (4 white spaces on the left). When I pasted it, Visual Studio was able to figure out that it needed indentation.

I would like to do the same thing with a macro. I do not want to use the clipboard as I have the text I want to insert in a variable (myText). I have something like:

Sub TemporaryMacro()

    Dim myText As String = "/// <summary>" _
    & vbCrLf & "/// My summary" _
    & vbCrLf & "/// </summary>" _
    & vbCrLf & "/// <param name='args'></param>"

    DTE.ActiveDocument.Selection.Text = myText

End Sub

When I run that macro I end up with:

class Program
{

    /// <summary>
    ///  <summary>
    ///  /// My summary
    ///  /// </summary>
    ///  /// <paramref name=" name='args'></param>"/></summary>
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {

    }
}

Note: I do get a different result.


I have also tried:

Public Module RecordingModule
    Sub TemporaryMacro()

        Dim myText As String = "/// <summary>" _
        & vbCrLf & "/// My summary" _
        & vbCrLf & "/// </summary>" _
        & vbCrLf & "/// <param name='args'></param>"

        DTE.ActiveDocument.Selection.Insert(myText)

    End Sub
End Module

which results in:

class Program
{

    /// <summary>
/// My summary
/// </summary>
/// <param name='args'></param>
    static void Main(string[] args)
    {

    }
}

I know I can place myText on the clipboard and then paste it. That does not make sense though. How can I achieve the same behavior as if I where pasting myText without having it to place it on the clipboard?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:20:27+00:00Added an answer on June 9, 2026 at 5:20 pm

    Finally found the solution:

    Dim myText As String = "/// <summary>" _
         & vbCrLf & "/// My summary" _
         & vbCrLf & "/// </summary>" _
         & vbCrLf & "/// <param name='args'></param>"
    
    DTE.ActiveDocument.Selection.Insert(myText)
    
    ' how many characters where inserted?
    ' Trying myText.Length gives incorrect results because visual studio counts \r\n as one character so we 
    ' use the regex \r\n|. to try to find first \r\n as one match and any other character as another match
    Dim insertLength As Integer = System.Text.RegularExpressions.Regex.Matches(myText, "(?>\r\n|.)").Count
    
    ' select the text that was just inserted
    DTE.ActiveDocument.Selection.CharLeft(True, insertLength)
    
    ' here comes the magic!
    DTE.ActiveDocument.Selection.SmartFormat()
    

    Edit

    I am making this edit to ask why this answer reserved down votes. If you refer to the question title it asks: Visual studio macro to insert text like when pasting when you paste text it maters where the cursor is located! I do not have to search for static void Main(string[] args) also I up voted the other answer cause I appreciate the help. If I would have known the answer earlier I would have turn this question into a bounty.

    Lastly the other solution does not work correclty… run that macro when I have comments at the top of the page and it does not work. It is helpful that’s why I up voted!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Summary: I have passed the name of the id select tag into an Array.
Many threads have access to summary . Each thread will have an unique key
I have a method that pulls a url name(varchar), a urlID(int) and its Enabled
I have the following area route registration method: /// <summary> /// Registers the area.
I have object Project in my entity. I create project by: public static void
I have column named summary (tinytext, utf8_turkish_ci). I know it can store 255 byte
Summary I have looked over the code the SpiderMonkey 'shell' application uses to create
I have the following validation summary control in the markup: <asp:ValidationSummary ID=vsValErrs CssClass=errors HeaderText=<div><%#
Summary A parent can have many children. How do you write a service such
--Summary (shortened)-- I have a controller that loads a profile object from the corresponding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.