kody7
10-01-2016, 05:21 PM
Hello Everyone, my name is Kody. I am very new to coding with VBA. Let me explain my situation as simply as possible.
I have some text in a word document. I need to format paragraph 1 (Top Line/Paragraph) until paragraph 2 (Bottom Line/Paragraph) and every paragraph in-between paragraph 1 and 2. The top line always starts with "WARNING" and the Bottom Line will always have this format "WG002.a 04-15-91" containing numbers and text.
I need the code to automatically scan the active document for these paragraphs and format accordingly. I have wrote code where I manually select/highlight the test and the run the subroutine to format the paragraphs as I wish. See below, I have included it.
Another problem I have is asking vba to search for paragraph the contains text and numbers (like paragraph 2) especially when I do not know what the numbers will be.
This is how the text in the active document would look like:
WARNING (First Paragraph I need to Format)
Text/wording (second Paragraph I need to format)
.... (Format paragraph)
.... (Format Paragraph)
.... (Format Paragraph)
... (Format Paragraph)
WG002.A 04-15-91 (Last line I need to format)
My code:
Dim WarningParagraphs as New ParagraphFormat
WarningParagraphs.Alignment = wdAlignParagraphLeft
WarningParagraphs.Borders.OutsideLineStyle = True
Selection.Paragraphs.Format = WarningParagraphs
With Selection
.Font.Name = "Times New Roman"
.Font.Size = 12
.Collapse Direction:=wdCollapseStart
.InsertBefore "Warning:"
.Font.Color = RGB (200,0,0)
.InsertParagraphBefore
.Font.Bold = True
End With
I have some text in a word document. I need to format paragraph 1 (Top Line/Paragraph) until paragraph 2 (Bottom Line/Paragraph) and every paragraph in-between paragraph 1 and 2. The top line always starts with "WARNING" and the Bottom Line will always have this format "WG002.a 04-15-91" containing numbers and text.
I need the code to automatically scan the active document for these paragraphs and format accordingly. I have wrote code where I manually select/highlight the test and the run the subroutine to format the paragraphs as I wish. See below, I have included it.
Another problem I have is asking vba to search for paragraph the contains text and numbers (like paragraph 2) especially when I do not know what the numbers will be.
This is how the text in the active document would look like:
WARNING (First Paragraph I need to Format)
Text/wording (second Paragraph I need to format)
.... (Format paragraph)
.... (Format Paragraph)
.... (Format Paragraph)
... (Format Paragraph)
WG002.A 04-15-91 (Last line I need to format)
My code:
Dim WarningParagraphs as New ParagraphFormat
WarningParagraphs.Alignment = wdAlignParagraphLeft
WarningParagraphs.Borders.OutsideLineStyle = True
Selection.Paragraphs.Format = WarningParagraphs
With Selection
.Font.Name = "Times New Roman"
.Font.Size = 12
.Collapse Direction:=wdCollapseStart
.InsertBefore "Warning:"
.Font.Color = RGB (200,0,0)
.InsertParagraphBefore
.Font.Bold = True
End With