Solved

VBA for Applications

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 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

26 Experts available now in Live!

Get 1:1 Help Now