Solved

VBA for Applications

Posted on 2013-01-24
5
265 Views
Last Modified: 2013-02-02
I have a Word 2010 Document I want to do the following via VBA. I want to search for the "1. ", or "2. "or really and "(Number)-Period-Space" and make the sentence it finds into a number bullet without indenting. Does anyone have a vba subroutine that will do that?


Here is a sample of the text:

1. Select the address PROT -> Procurement and sourcing
2. Enter Area Page node: Procurement and sourcing -> Common -> Purchase requisitions -> All purchase requisitions.
3. Enter the Purchase requisition -> New -> Purchase requisition button.
4. Enter Name
5. Enter Requested date
6. Enter the OK button.
0
Comment
Question by:bcruse32347
  • 3
  • 2
5 Comments
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 38817808
Hi,

Would the LISTNUM fields be an option for you.

Regards
0
 
LVL 2

Author Comment

by:bcruse32347
ID: 38818487
I do not have a preference for the method as long as it goes thru the document and finds the sentences, no matter how many there are and sets them as numbered bullets. I have tried using :

Selection.Range.ListFormat.ApplyNumberDefault

like this:

Sub formatnumbers()

     
   Selection.Find.ClearFormatting
   
    With Selection.Find
     Do While .Execute(FindText:="<([0-9])" & ".", Forward:=True) = True

        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
       
 Selection.Expand Unit:=wdSentence
  Selection.Range.ListFormat.ApplyNumberDefault
    Loop
    End With
   


End Sub

But I cant get it to loop thru and find the sentences.
0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 38824390
Hi,

I've changed you code

Use Wildcards, if you want to use regex
Expand by Paragraph, since number bullets work per paragraph not line

the macro doesn't read the number it replaces it with the next available number if it is the same, if you have a gap (7, not8 and then 9), it will insert before the number( in the example "8." tab "9.").

Sub formatnumbers()
    
    Selection.Find.ClearFormatting
    
    With Selection.Find
        Do While .Execute(FindText:="(<[0-9]{1;3}. )", Forward:=True, MatchWildcards:=True) = True
            Selection.Expand Unit:=wdParagraph
            Selection.Range.ListFormat.ApplyNumberDefault
        Loop
    End With
    
End Sub

Open in new window


Regards
0
 
LVL 2

Accepted Solution

by:
bcruse32347 earned 0 total points
ID: 38828133
This is what finally worked properly:

Dim k As Integer
With Selection.Find
  .ClearFormatting
  .Text = "([0-9]{1,3})."
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchAllWordForms = False
  .MatchSoundsLike = False
  .MatchWildcards = True
  .Execute
  Do While .Found
    k = k + 1

    Selection.Range.ListFormat.ApplyNumberDefault
   
   
   
    .Execute

  Loop

End With
0
 
LVL 2

Author Closing Comment

by:bcruse32347
ID: 38846401
Provided solution has problem with pattern match.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now