Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA for Applications

Posted on 2013-01-24
5
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

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 52

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

704 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