View Single Post
 
Old 08-07-2021, 07:26 PM
Bikram Bikram is offline Windows 10 Office 2007
Advanced Beginner
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Post Format text between two styles

I am beginner in vba hoping for some guidelines to automate my daily task. So, any help would be greatly appreciated.

Here is my code

Sub find_and_format()
Dim doc As Document
Dim rng As Range


Set doc = Application.ActiveDocument
Set rng = doc.Content

With rng.find
.ClearFormatting
.Text = "Answer"
.Style = ActiveDocument.Styles("ans")
.Format = False
.MatchAllWordForms = False
.MatchWildcards = False
.MatchCase = False
.Wrap = wdFindContinue
End With


Do Until rng.find.Execute = False
Selection.MoveDown unit:=wdParagraph, Count:=1
Selection.Style = ActiveDocument.Styles("t")
Selection.MoveDown unit:=wdParagraph, Count:=1
'do while manual numbering is found
Do While Selection.Range.ListFormat.ListType = wdListSimpleNumbering
' and then i want to select and change the autonumbering to manual numbering
Selection.Range.ListFormat.ConvertNumbersToText
Selection.Style = ActiveDocument.Styles("tt")

' or repeat this process until another style is found
Loop
'can i access the range between a style to another style and then format it??


Loop

'i have attached a sample file



End Sub
Attached Files
File Type: docx Sample.docx (21.3 KB, 9 views)
Reply With Quote