Need help regarding Formatting multiple paragraphs individually in word using vba

karthik82.vk

New Member
Joined
Aug 21, 2011
Messages
15
Hi,

I am creating a vba app for automating word. I have separate paragraphs and i want to format them individually. I got some code fromthe microsoft community to help me but the problem i am facing with the code i am unable to format the paragraphs individually. Even though i code each paragraph with different formatting i am getting the output like the initial formatting style i fixed is being applied to all the paragraph in the document.

The desired output i require is similar to the one shown in the below image


4463


The output i am getting with my current code is something like all the paragraphs are getting aligned in the center itself. i am unable to align them individually.
The code i am currently using is


'
'Insert a paragraph for the Protocol Title
'** \endofdoc is a predefined bookmark.
Set oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\EndofDoc").Range)
oPara2.Range.Font.Bold = True
oPara2.Range.Font.Name = "Arial"
oPara2.Range.Font.Size = 10
oPara2.Range.Text = "T I T L E"
oPara2.Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
oPara2.Borders(wdBorderBottom).Visible = True
oPara2.Borders(wdBorderBottom).Color = wdColorBlack
'oPara2.Range.Font.Spacing = 4
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter
Selection.Collapse Direction:=wdCollapseEnd
oPara2.Range.InsertBreak Type:=wdSectionBreakContinuous


'Insert another paragraph for Protocol Title.
Set oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\EndofDoc").Range)
oPara3.Range.Font.Name = "Arial"
oPara3.Range.Font.Size = 9
oPara3.Range.Paragraphs(1).Alignment = wdAlignParagraphLeft
oPara3.Range.Text = "<insert protocol="" title="" from="" rsp="" user="" requirements="" in="" this="" section="">"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 6
oPara3.Range.InsertParagraphAfter
oPara3.Range.Text = vbCrLf

'Insert a paragraph for reference details
'** \endofdoc is a predefined bookmark.
Set oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\EndofDoc").Range)
oPara4.Range.Font.Bold = True
oPara4.Range.Font.Name = "Arial"
oPara4.Range.Font.Size = 10
oPara4.Range.Text = "R E F E R E N C E D E T A I L S"
oPara4.Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
oPara4.Borders(wdBorderBottom).Visible = True
oPara4.Borders(wdBorderBottom).Color = wdColorBlack
'oPara4.Range.Font.Spacing = 4
oPara4.Format.SpaceAfter = 6
oPara4.Range.InsertParagraphAfter
Selection.Collapse Direction:=wdCollapseEnd
oPara4.Range.InsertBreak Type:=wdSectionBreakContinuous


'Insert another paragraph for reference details.
Set oPara5 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\EndofDoc").Range)
oPara5.Range.Font.Name = "Arial"
oPara5.Range.Font.Size = 9
oPara5.Range.Paragraphs(1).Alignment = wdAlignParagraphLeft
oPara5.Range.Text = "<insert refence="" details="" like="" randomization="" type,="" stratification="" factors,="" block="" size,="" treatment="" arm="" -="" kittype="" mapping="" tables,="" drug="" dispensation="" tables="" etc..="" from="" rsp="" user="" requirements="" in="" this="" section="">"
oPara5.Range.Font.Bold = False
oPara5.Format.SpaceAfter = 6
oPara5.Range.InsertParagraphAfter
oPara5.Range.Text = vbCrLf


'Insert a paragraph for reference documents.
'** \endofdoc is a predefined bookmark.
Set oPara6 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\EndofDoc").Range)
oPara6.Range.Font.Bold = True
oPara6.Range.Font.Name = "Arial"
oPara6.Range.Font.Size = 10
oPara6.Range.Text = ""
oPara6.Range.Paragraphs(1).Alignment = wdAlignParagraphCenter
oPara6.Borders(wdBorderBottom).Visible = True
oPara6.Borders(wdBorderBottom).Color = wdColorBlack
'oPara6.Range.Font.Spacing = 4
oPara6.Format.SpaceAfter = 6
oPara6.Range.InsertParagraphAfter
Selection.Collapse Direction:=wdCollapseEnd
oPara6.Range.InsertBreak Type:=wdSectionBreakContinuous

'Insert another paragraph for reference documents.
Set oPara7 = oDoc.Content.Paragraphs.Add
oPara7.Range.Font.Name = "Arial"
oPara7.Range.Font.Size = 9
oPara7.Range.Paragraphs.Alignment = wdAlignParagraphLeft
oPara7.Range.Text = "<insert the="" reference="" documents="" used="" to="" perform="" qmr="" review="" in="" this="" section.="" format:="" fds="" version="" <version="" no="">, <version date=""> >"
oPara7.Range.Font.Bold = False
oPara7.Format.SpaceAfter = 6
oPara7.Range.InsertParagraphAfter
oPara7.Range.Text = vbCrLf

<insert protocol="" title="" from="" rsp="" user="" requirements="" in="" this="" section=""><insert reference="" details="" from="" rsp="" user="" requirements="" in="" this="" section=""><insert the="" reference="" documents="" used="" to="" perform="" qmr="" review="" in="" this="" section.="" format:="" fds="" version="" <version="" no=""><version date="">
<insert protocol="" title="" from="" rsp="" user="" requirements="" in="" this="" section=""><insert reference="" details="" from="" rsp="" user="" requirements="" in="" this="" section=""><insert the="" reference="" documents="" used="" to="" perform="" qmr="" review="" in="" this="" section.="" format:="" fds="" version="" <version="" no=""><version date="">

the output i am getting is the one below in the given image

4467



Can someone please let me know whats wrong in the code i am using and help me with the correct code to format the paragraphs with different styles and alignment individually?</version></insert></insert></insert></version></insert></insert></insert></version></insert></insert></insert>
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top