Adjust line spacing in Word document

Posted on 2009-04-23
Last Modified: 2012-05-06
Greetings Experts,

I have an application that creates a word document.  I need to be able to set the default line spacing for this document from double to single.  I know the proper technique, however I am getting an error.

error message:
"The measurement must be between 0.7 pt and 1584 pt."

occurs on line:
.ParagraphFormat.LineSpacing = Word.WdLineSpacing.wdLineSpaceSingle

Any help you can lend in this matter would be appreciated.  Thank you in advance.
Dim WordApp As New Word.Application

Dim doc As Word.Document = WordApp.Documents.Add()

With WordApp.Selection

            .ParagraphFormat.LineSpacing = Word.WdLineSpacing.wdLineSpaceSingle



            .Font.Size = 12

            .Font.Bold = CInt(True)

            .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter

            .TypeText("CREDIT REFERENCE REPLY")


            .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft

            .Font.Bold = CInt(False)

            .Font.Size = 10

            .TypeText("Date:" & vbTab & vbTab & "05/22/09" & vbCrLf)

            .TypeText("From:" & vbTab & vbTab & "Credit Department" & vbCrLf)

            .TypeText("To:" & vbTab & vbTab & "Fax Number" & vbCrLf)

            .TypeText("Attn:" & vbTab & vbTab & "Contact Name" & vbCrLf)

            .TypeText("Subject:" & vbTab & vbTab & "Credit Reference Response")


            Dim srCreditLegal As StreamReader

            Dim strCreditLegal As String

            srCreditLegal = New StreamReader("C:\Credit Legal.txt")


                strCreditLegal = srCreditLegal.ReadToEnd()

                .Font.Size = 7


            Catch ex As Exception

                MessageBox.Show("Error reading Credit Legal file" & vbCrLf & ex.Message)

            End Try



End With


End Sub

Open in new window

Question by:gwosgood
    LVL 11

    Expert Comment

    instead of
     .ParagraphFormat.LineSpacing = Word.WdLineSpacing.wdLineSpaceSingle

     .ParagraphFormat.LineSpacing = 1
    LVL 2

    Author Comment

    Hehe, I tried that, lets just say it did not turn out well.  I needed a magnifying glass to read the text.

    I guess I need to know what the pt equivalent of single spacing is.  Any idea on how to find that?
    LVL 11

    Accepted Solution

    I dnt kno much abt it and I was searching in net and I found it.
    use this before the line spacing and try

    .LineSpacingRule = wdLineSpaceExactly

    Check this link
    LVL 2

    Author Comment

    Ahah, a combination of the two is my answer

    .LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle

    works perfectly!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now