Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2021, 04:54 AM
Shelley Lou Shelley Lou is offline Help with macro - inserting tab Windows 10 Help with macro - inserting tab Office 2016
Advanced Beginner
Help with macro - inserting tab
 
Join Date: Dec 2020
Posts: 69
Shelley Lou is on a distinguished road
Default Help with macro - inserting tab

I've run into a problem with a macro I have developed (with help from very kind people on here also). Please see image of before and after the macro is run.


The macro should insert a tab at the beginning of paragraphs that start with (a), (i) (1), a), 1), 100 etc. The macro runs fine except when the paragraph starts with a number. Can anyone help with the code below to insert a tab before a number (please note this is just an extract from the main macro). Thanks, Shelley

Code:
 'insert tab at beginning of paragraph with a bracket e.g. (a), (i), (1)
    With oRng.Find
    .Text = "^p("
    .Replacement.Text = "^p^t("
    .Execute Replace:=wdReplaceAll
  End With
  'insert tab at beginning of paragraph e.g a), 1), i), 100 etc.
    With oRng.Find
    .Text = "[^p]\([a-zA-Z0-9][)]"
    .Replacement.Text = "^p^t"
    .Execute Replace:=wdReplaceAll
  End With
Attached Images
File Type: jpg Definitions (before macro).JPG (94.8 KB, 14 views)
File Type: jpg Definitions (after macro).JPG (102.3 KB, 13 views)
Reply With Quote
  #2  
Old 02-16-2021, 06:36 AM
gmayor's Avatar
gmayor gmayor is offline Help with macro - inserting tab Windows 10 Help with macro - inserting tab Office 2019
Expert
 
Join Date: Aug 2014
Posts: 3,584
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

It appears from your illustrations that you want to begin every paragraph with a tab thus

Code:
With orng.Find
    .MatchWildcards = False
    .Text = "^p"
    .Replacement.Text = "^p^t"
    .Execute Replace:=wdReplaceAll
End With
If you only want to process the 'numbered' paragraphs that match your comments then
Code:
    'insert tab at beginning of paragraph with a bracket e.g. (a), (i), (1)
    With orng.Find
        .MatchWildcards = True
        .Text = "^13(\([a-z0-9]{1,}\))"
        .Replacement.Text = "^p^t\1"
        .Execute Replace:=wdReplaceAll
    End With
    
    'insert tab at beginning of paragraph e.g a), 1), i), 100 etc.
    With orng.Find
        .MatchWildcards = True
        .Text = "^13([a-z0-9\)]{1,})"
        .Replacement.Text = "^p^t\1"
        .Execute Replace:=wdReplaceAll
    End With
See Replace using wildcards
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-16-2021, 07:01 AM
Shelley Lou Shelley Lou is offline Help with macro - inserting tab Windows 10 Help with macro - inserting tab Office 2016
Advanced Beginner
Help with macro - inserting tab
 
Join Date: Dec 2020
Posts: 69
Shelley Lou is on a distinguished road
Default Help with macro - inserting tab

Hi Graham, the second option works perfectly, thank you very much again for your help, much appreciate, best wishes Shelley
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with macro - inserting tab Is it possible to make a macro for inserting a 'division box?' Rayroshi Word 1 08-30-2018 06:40 PM
Macro-inserting text box BLUEPUPIL Word VBA 14 04-16-2018 06:59 AM
Help with macro - inserting tab Macro for inserting and formatting headers and footers Mike_Lennox Word VBA 4 10-06-2016 12:10 AM
Help with macro - inserting tab Need Macro for Find and Replace, Inserting logo in Ms-Word. Aswinraj Word VBA 1 06-05-2016 04:33 PM
Help with macro - inserting tab Inserting key strokes with a macro line ACA Word VBA 4 12-03-2012 04:40 AM

Other Forums: Access Forums

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


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