Quote:
Originally Posted by Guessed
For the content you provided, this macro works
Code:
Sub Macro1()
Dim aRng As Range, aSty As Style
Set aRng = ActiveDocument.Range
Set aSty = ActiveDocument.Styles("Note Heading")
aSty.Font.Name = "Calibri"
aSty.Font.Size = 8
With aRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Style = aSty
.Text = "door type:"
.Replacement.Text = "Door Type:"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = True
Do While .Execute(Replace:=wdReplaceOne)
aRng.Paragraphs(1).Range.Font.Reset
aRng.Collapse Direction:=wdCollapseEnd
Loop
End With
Set aRng = ActiveDocument.Range
With aRng.Find
.Text = "door material:"
.Replacement.Text = "^pDoor Material:"
.Execute Replace:=wdReplaceAll
End With
End Sub
|
This is superb. Thank you Andrew.
Can a slight adjustment be made?
The original sentence either has a space before it or some text which is joined onto it (like xxxDoor type).
Is there a way for the code to remove any space before the word, or separate the previous word from 'Door', and then move the whole thing onto another line anyway?
So:
xxxdoor type: Flat Entry Door door material: Wood
would become:
xxx
Door Type: Flat Entry Door
Door Material: Wood
and
door type: Flat Entry Door door material: Wood
Becomes
Door Type: Flat Entry Door
Door Material: Wood
Can an adjustment like this be made in the code?
Really helpful.
Thanks,
JH