Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2021, 04:00 AM
Shelley Lou Shelley Lou is offline VBA Find and Replace for sub levels Windows 10 VBA Find and Replace for sub levels Office 2016
Competent Performer
VBA Find and Replace for sub levels
 
Join Date: Dec 2020
Posts: 163
Shelley Lou is on a distinguished road
Default VBA Find and Replace for sub levels

Hi, I'm looking to update the code below. It needs to insert a tab at the beginning of sentences for sub-levels which it currently does as it stands at the moment. I want the macro to also convert any instances of a single bracket sub level e.g. a), i), A), 1) to (a), (i), (A), (1) but I can't seem to fathom how to do this. Can anyone help at all? Thanks



Sub Level Test Doc.docx


Code:
Set orng = ActiveDocument.Range
 'insert tab at beginning of paragraph with a bracket e.g. (a), a), (i), i), (1), 1)
  With orng.Find
        .MatchWildcards = True
        .Text = "^13(\([a-z0-9]{1,}\))"
        .Replacement.Text = "^p^t\1"
        .Execute Replace:=wdReplaceAll
    End With
Reply With Quote
  #2  
Old 06-20-2021, 04:17 PM
macropod's Avatar
macropod macropod is offline VBA Find and Replace for sub levels Windows 10 VBA Find and Replace for sub levels Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For example:
Code:
With ActiveDocument.Range.Find
  .MatchWildcards = True
  .Text = "^13([\(a-z0-9]@\))"
  .Replacement.Text = "^p^t\1"
  .Execute Replace:=wdReplaceAll
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-21-2021, 12:45 AM
Shelley Lou Shelley Lou is offline VBA Find and Replace for sub levels Windows 10 VBA Find and Replace for sub levels Office 2016
Competent Performer
VBA Find and Replace for sub levels
 
Join Date: Dec 2020
Posts: 163
Shelley Lou is on a distinguished road
Default VBA Find and Replace for sub levels

Hi Macropod, many thanks for this, much appreciated
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you use the find and replace tool to find dates and times in Excel 2013? Jules90 Excel 3 04-14-2020 07:40 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
VBA Find and Replace for sub levels Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
VBA Find and Replace for sub levels Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
VBA Find and Replace for sub levels Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:24 PM.


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