How can I create a MS Word document in PowerShell and set the paragraph/line spacing to none?

Question:

I am looking to create a PowerShell script that will generate a Word document. It works as expected but when I run the script there is a space or a line break between “My Document: Title” and “Date: 01-07-2014”. The result looks like this:

I want it to look like this:

How can I write into this script a way to remove spaces within paragraphs? What I mean is, I want to set the paragraph spacing to single in PowerShell (not in Word as a default) By the way, if i do not add the $selection.TypeParagraph() before the “Date: $date”, the result looks like this:

As in, there is no carriage return at all. The goal is to have one carriage return but no space after that carriage return. Here is the script.

Answer:

I think what you want is to change the Paragraph style from “Normal” to “No Spacing”.

The start of your code is the same:

Then you want to change the paragraph style to “No Spacing”

And then you can carry on with the rest of your code:

Source:

How can I create a MS Word document in PowerShell and set the paragraph/line spacing to none? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply