none
Inappropriate paragraph markers caused by using vbNewLine RRS feed

  • Question

  • Hi all,

    I am currently trying to create a word document with multiple paragraphs using oDoc.Paragraphs(p).Range.Text, where p is an increasing variable for each paragraph and I am typically setting the paragraph's text with a string.

    My problem occurs when I want to create a paragraph with multiple lines, so in creating my string I use '& vbNewLine & ', which, when creating the Word document, Word mistakenly views these new lines as new paragraphs.  So the paragraphs I want to follow get blended in with the first paragraph.  Here is the current code:

            p = 1
            oDoc.Paragraphs(p).Range.Text = "SPECIFICATION REVIEW/DATABASE INPUT FORM"
            oDoc.Paragraphs(p).Range.Font.Underline = True
            oDoc.Paragraphs(p).Range.Font.Bold = True
            oDoc.Paragraphs(p).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
            oDoc.Paragraphs(p).Range.InsertParagraphAfter()
    
            p += 1
            oDoc.Paragraphs(p).Format.KeepTogether = True
            Dim String2Para As String = "GT-" & gtstring & " NETWORK # " & networkstring & " Design # " & designstring & vbCr &
                "MVA " & mvastring & " Customer (Bill To) " & customerstring & vbCr &
                "Consulting Engineer " & consultingengineerstring & " EE Designer " & eedesignerstring & " Initial Scheduled AA Date " & aadatestring & vbCr &
                "Detail " & detailstring & " Ship Date " & shipstring & " To Shop Date " & toshopstring & vbCr
            oDoc.Paragraphs(p).Format.KeepTogether = True
            oDoc.Paragraphs(p).Range.Font.Bold = False
            oDoc.Paragraphs(p).Range.Text = String2Para
            oDoc.Paragraphs(p).Range.InsertParagraphAfter()
    
            p += 1
            oDoc.Paragraphs(p).Range.Text = "I. CODES AND STANDARDS"
            oDoc.Paragraphs(p).Style = HeadingStyle
            oDoc.Paragraphs(p).Range.Font.Bold = True
            oDoc.Paragraphs(p).Range.Font.Name = "Arial"
            oDoc.Paragraphs(p).Range.Font.Color = Word.WdColor.wdColorBlack
            oDoc.Paragraphs(p).Range.InsertParagraphAfter()
    
    

    You can currently see that I am trying to use 'vbCr' instead of 'vbNewLine', but it doesn't make a difference at all.  The first line is printed fine, then the line "I. CODES AND STANDARDS" gets blended in with "MVA" etc., and "Consulting Engineer" gets blended with the paragraph after.  What can I do to fix this?  I have thought about placing each paragraph at the end of the document using the \endofdoc bookmark but have been unsuccessful using this with Paragraphs().

     

    Any suggestions?

    Tuesday, November 22, 2011 9:29 PM

Answers

  • Instead of vbNewLine try using vbVerticalTab
    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by JoshMan987 Wednesday, November 23, 2011 1:35 PM
    Tuesday, November 22, 2011 10:30 PM

All replies

  • Instead of vbNewLine try using vbVerticalTab
    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by JoshMan987 Wednesday, November 23, 2011 1:35 PM
    Tuesday, November 22, 2011 10:30 PM
  • Brilliant, thank you!  I knew it was simple, just had to find the right tool.
    Wednesday, November 23, 2011 1:35 PM