![]() |
|
|
|
#1
|
||||
|
||||
|
Hmm, it can be done but requires a more involved approach built off Graham's search method. This is my first attempt at it.
Code:
Sub HilitePartNumsHyph()
Dim rngWord As Range, aRng As Range, sWord As String
Dim oRng As Range, oNum As Range, rngFrag As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(findText:="[0-9]{1,}", MatchWildcards:=True)
Set oNum = oRng.Words(1)
'oNum.Select 'XXXX Testing Only XXX
sWord = UCase(Trim(oNum.Text))
If sWord Like "*[A-Z]*" Then 'If there is a letter included it is a part num
Set rngFrag = oNum.Words.Last.Next
'rngFrag.Select 'XXXX Testing Only XXX
If rngFrag.Text = "-" Then
rngFrag.MoveEnd Unit:=wdWord, Count:=1
oNum.End = rngFrag.End
oNum.Select 'XXXX Testing Only XXX
End If
oNum.HighlightColorIndex = wdYellow
Debug.Print oNum 'This is the output list
End If
oRng.Start = oNum.End
Loop
End With
End Sub
It doesn't care what comes after the hyphen, as long as Word considers it to be the 'next word'. This means it wont find N50-V12345-N51 as a SINGLE item, nor will it find 123-NNN or NNN-123. It will find N50-- and N50-8908098
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#2
|
|||
|
|||
|
That did it! Andrew you are awesome! Graham I didn't forget about you either, I added to both the reputations on all the comments for you guys. Thanks!
|
|
| Tags |
| numeric, phonetic, word macros |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Creating your own Section Headings using Numbers and letters and linking to the TOC
|
rehahm | Word | 4 | 10-07-2015 10:20 AM |
Creating a TOC with sequential letters instead of page numbers at the right margin
|
shansen | Word | 1 | 03-11-2014 12:43 PM |
| Look up cell values with mixed number and letters | Cardinal2 | Excel | 1 | 02-10-2013 01:40 AM |
Captions mixing letters and numbers
|
trew | Word | 7 | 11-21-2012 12:54 AM |
Creating TOC with letters and numbers
|
tanababa | Word | 1 | 04-28-2011 01:35 AM |