Search code examples
c#office-interop

What's the keystroke for SHIFT+ENTER to be written into a Interop.Word Document


I'm writing text into a Interop.Word document and I would like to add one paragraph that has 2 sentences separated by SHIFT+ENTER (which makes the text be closer to each other), instead then a a full ENTER.

Is there a special character or way to achieve so?


Solution

  • When looking for answers about Office products, you should always start with recording a macro and seeing what is produced. When I did this, I typed "blah<SHIFT+ENTER>blah" then stopped recording. The resulting macro looked like this.

    Sub Macro1()
        Selection.TypeText Text:="blah" & Chr(11) & "blah"
    End Sub
    

    Looks like you just need to insert a char 11 in your text.

    ==========
    So in C# this would be something like:

    string s = "first line" + Convert.ToChar(11) + "Second line";