Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 11-22-2023, 09:30 AM
Jetheat Jetheat is offline Replacing a Sentence with New Format Mac OS X Replacing a Sentence with New Format Office 2016 for Mac
Novice
Replacing a Sentence with New Format
 
Join Date: Dec 2013
Posts: 21
Jetheat is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sentence Template michissimo Word 1 11-19-2020 05:53 PM
Replacing a Sentence with New Format VBA: Set two styles in one sentence jeffreybrown Word VBA 6 09-07-2018 03:46 PM
Replacing a Sentence with New Format I want to know how to format a sentence after beginning it with an automatic number spirituel Word 2 09-29-2015 01:50 AM
Replacing a Sentence with New Format End of sentence puncuation. nrsmd Word 2 07-04-2015 10:33 PM
Replacing a Sentence with New Format Delete does not bring second sentence closer to first sentence Andoheb Word 29 07-03-2014 01:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft