PDA

View Full Version : [SOLVED:] Engineering units identifier macro



Programmer_n
04-21-2016, 04:00 AM
I am working on a macro to identify numbers and highlight in my document.

Using .Text = "[0-9]{1,}" to find the numbers and oRng.HighlightColorIndex = wdRed to highlight the numbers i am able to highlight the numbers.

Now, my case is to search and highlight the units when there are units like

3 m/s
45.13 kWh
45 m3

So, the search would be a mixture of decimal,small letters, upper case, superscript and a space between number and unit. I want to write a
.Text to accommodate this features. Is it possible to accommodate such a deep query within .Text? If yes, Please help.

Programmer_n
04-21-2016, 05:12 AM
.Text = [0-9]*[A-z]* seems to solve the problem for a mixture of decimal,small letters, upper case, superscript and a space between number and unit., but still testing it in many scenarios.

Note: there is a space after second *

gmaxey
04-21-2016, 01:31 PM
What you have will certainly find your examples. It won't find one of the those terms if it is at the end of a sentence. You might try:

[0-9]*[A-z]*[ .^13]

It will also find stuff like 123 Maple Avenue. Can you live with that?

Programmer_n
04-22-2016, 05:41 AM
What you have will certainly find your examples. It won't find one of the those terms if it is at the end of a sentence. You might try:

[0-9]*[A-z]*[ .^13]

It will also find stuff like 123 Maple Avenue. Can you live with that?

Thanks for the code. My approach to macro is not 100 % perfection, even if it saves 80% of my attention span, It makes my life easy for sure.