none
how to mimic a word macro in VSTO code RRS feed

  • Question

  • In a word macro I see the following code after I turn the macro recorder on and type a line of text, shift enter, then another line of text:

        Selection.TypeText Text:="Company Name" & Chr(11) & "Person name" & Chr(11 _
            ) & "Address line 1"
        Selection.TypeParagraph
        Selection.TypeText Text:="Company Name" & Chr(11)
    

    how to mimic this in VSTO?

    var r = doc.Content ;
    r.InsertAfter("CompanyName" + 0x0b + "Person name" + 0x0b + "Address  line 1" ) ;

    does not work out very well. I get a single line of text.

    and
    r.InsertAfter("Company Name" + "\n")  etc

    inserts the lines with paragraph size spacing between them.

    thanks,


    Saturday, November 17, 2012 9:44 PM

Answers

All replies

  • I see that I can range.set_Style("No Spacing") to set the spacing of all the lines in the range.  Still interested to know how lines can be inserted into the range with line spacing and not paragraph spacing.

    var r = doc.Range( ref missing, ref missing ) ;
    r.InsertAfter( "line 1" + "\n") ;
    r.InsertAfter( "line 2" + "\n") ;
    r.InsertAfter( "line 3" + "\n") ;
    r.set_Style("No Spacing") ;
    

    Saturday, November 17, 2012 11:54 PM
  • Shift + Enter = new line, which in C# can be represented by: \v

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Steve Richter Sunday, November 18, 2012 4:18 PM
    Sunday, November 18, 2012 7:30 AM
    Moderator