Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA for Applications

Posted on 2013-01-24
5
Medium Priority
?
286 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 53

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1500 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 53

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

916 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