Solved

VBA for Applications

Posted on 2013-01-24
5
270 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 49

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 49

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

772 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