• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4635
  • Last Modified:

Adjust line spacing in Word document

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
 
            .InlineShapes.AddPicture("C:\CompanyLogo.JPG")
            .TypeParagraph()
 
            .Font.Size = 12
            .Font.Bold = CInt(True)
            .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
            .TypeText("CREDIT REFERENCE REPLY")
            .TypeParagraph()
 
            .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")
            .TypeParagraph()
 
            Dim srCreditLegal As StreamReader
            Dim strCreditLegal As String
            srCreditLegal = New StreamReader("C:\Credit Legal.txt")
            Try
                strCreditLegal = srCreditLegal.ReadToEnd()
                .Font.Size = 7
                .TypeText(strCreditLegal)
            Catch ex As Exception
                MessageBox.Show("Error reading Credit Legal file" & vbCrLf & ex.Message)
            End Try
 
            srCreditLegal.Close()
            .TypeParagraph()
 
End With
 
doc.ActiveWindow.Activate()
 
End Sub

Open in new window

0
gwosgood
Asked:
gwosgood
  • 2
  • 2
1 Solution
 
srikanthreddyn143Commented:
instead of
 .ParagraphFormat.LineSpacing = Word.WdLineSpacing.wdLineSpaceSingle

try
 .ParagraphFormat.LineSpacing = 1
0
 
gwosgoodIT MgrAuthor Commented:
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?
0
 
srikanthreddyn143Commented:
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
http://www.jojo-zawawi.com/code-samples-pages/code-samples.htm
0
 
gwosgoodIT MgrAuthor Commented:
Ahah, a combination of the two is my answer


.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle

works perfectly!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now