PDA

View Full Version : Guidance with complex formatting problem



ALIMS
05-29-2013, 08:42 AM
:banghead: After scouring the web searching for a solution to help automate what could be defined as the “7th circle of repetition hell” :devil2: , I came across this site and found some very hopeful posts by some of your members and am hoping that I can gain some help with my project.

My problem lies in how to make changes to individual lines contained within multiple blocks of formatted text. Here is an example:

SPAD-6000-ADMN [N/A] N/A N/A B N/A C N/A Times: 1
TEC. N/A
Task. Completed all 2000-4000 level tasks.
Requirement. N/A
Performance Standard. Completed all 2000-4000 level tasks.
Prerequisites. N/A
External Syllabus Support. N/A
Academics:
References. N/A
Lectures. N/A
IMIs. N/A
Exams. N/A
T&R Task Sign-Off Authority. Work Center Supervisor

The standard formatting options for ALL blocks as shown above is:
1. font: courier new 10 point
2. Line spacing options: 6 points before and 0 points after
3. Each line set to 1 inch margin.
4. Each line has a heading, which should be underlined (minus the period or the colon after Academics).
5. Each heading should end with a period (or a colon in the case of academics) and be preceded with TWO spaces.

What is the best recommendation to create a macro that will loop through each block of text, check the various formatting as listed above and make corrections where necessary? I am by no means a “programmer”, so some of the object oriented terms and techniques on the Microsoft Developer forums tend to get lost in translation. I have more of a procedural understanding of how to accomplish automated tasks such as this. I have collected a few macro “gems” but am unable to cobble them together to create something that I can understand, extend and modify.
Any assistance would be greatly appreciated. :help

ALIMS
05-31-2013, 06:03 AM
Posted below are the snippets I am looking at trying to implement. Just not sure how to begin coding the conditions in which to apply them.

For example,

if line begins with TEC
SetLeftIndentZero()
SetLineSpacing()
RemoveImproperUnderline()

if line begins with ... etc, etc..


Sub SetLineSpacing() ' Set Line Spacing to 0 before and 6 after
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 6
.LineSpacingRule = wdLineSpaceSingle
End With
End Sub
Sub SetLeftIndentZero() ' Set Line Indent to zero
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
End With
End Sub
Sub SetLeftIndentQuarter() ' Set Line Indent to 1/4 inch
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.25)
End With
End Sub
Sub SetLeftIndentHalf() ' Set Line Indent to 1/2 inch
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
End With
End Sub
Sub TwoSpaces()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([.\:]) {1,}"
.Replacement.Text = "\1 "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub SpaceAfterPeriod()
'Inserts a space after the period when the text is $.$ where $ represents any letter.
'Does not insert the space, if a space already exists as in $. $
'Does not insert a space if a number precedes or follows the period.
With ActiveDocument.Range.Find
.Text = "([A-Za-z].)([A-Za-z])"
.MatchWildcards = True
.Wrap = wdFindContinue
.Replacement.Text = "\1 \2"
.Execute Replace:=wdReplaceAll
End With
End Sub
Sub RemoveImproperUnderline() 'from modified post by Greg Maxey
Dim oRng As Word.Range
Dim arrWords
Dim i As Long
arrWords = Array(".", ". ", ". ", ":", ": ", ": ")
For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrWords(i)
.MatchWholeWord = True
.Replacement.Font.Underline = False
.Execute Replace:=wdReplaceAll
End With
Next
End Sub


Anxiously awaiting come constructive feeback : pray2: