473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help With Writing A Word Macro

I am trying to write a word macro that scans the documents and highlights all the numbers that are less then .95
is this possible to do using a word macro?

i guess i really only need the command that selects a range of numbers.
like if number < .95 or something like that. i am not really a vba person and am used to writing only c++ and python scripts.
Oct 10 '07 #1
5 1683
kadghar
1,295 Expert 1GB
I am trying to write a word macro that scans the documents and highlights all the numbers that are less then .95
is this possible to do using a word macro?

i guess i really only need the command that selects a range of numbers.
like if number < .95 or something like that. i am not really a vba person and am used to writing only c++ and python scripts.
i dont know if there's an easy method, but with a DO and a couple of IF it can be done. Something like:

Expand|Select|Wrap|Line Numbers
  1. Sub prueba()
  2. Dim i As Double
  3. Dim j As Integer
  4. Dim Dou1 As Double
  5. Selection.Start = 0
  6. Selection.End = 0
  7. For i = 1 To ActiveDocument.Characters.Count
  8.     j = Asc(ActiveDocument.Characters(i))
  9.     If (j >= 48 And j <= 57) Or j = 46 Then
  10.         If Selection.End < i - 1 Then
  11.             Selection.Start = i - 1
  12.             Selection.End = i
  13.         Else
  14.             Selection.End = i
  15.         End If
  16.     Else
  17.         If Selection.End = i - 1 Then
  18.             Dou1 = Selection.Text
  19.             If Dou1 < 0.95 Then
  20.                 Selection.Font.Bold = True
  21.             End If
  22.         End If
  23.     End If
  24. Next
  25. End Sub
HTH
Oct 10 '07 #2
i am getting a type mismatch at the
Expand|Select|Wrap|Line Numbers
  1. Dou1 = Selection.Text
  2.  
The file does contain letters and numbers and different characters in it. Could there be a mismatch because i, j, Dou1 are all defined as numbers. Also, i am sure there is a good reason for it, but why is this line in the code and what does it do:

Expand|Select|Wrap|Line Numbers
  1. If (j >= 48 And j <= 57) Or j = 46 Then
  2.  
Oct 10 '07 #3
kadghar
1,295 Expert 1GB
i am getting a type mismatch at the
Expand|Select|Wrap|Line Numbers
  1. Dou1 = Selection.Text
  2.  
The file does contain letters and numbers and different characters in it. Could there be a mismatch because i, j, Dou1 are all defined as numbers. Also, i am sure there is a good reason for it, but why is this line in the code and what does it do:

Expand|Select|Wrap|Line Numbers
  1. If (j >= 48 And j <= 57) Or j = 46 Then
  2.  
actually the error was because there are periods without numbers. because it searches for numbers an dots, and if it finds a dot without a number and try it as a number it will show you the error. so all you have to do is in the line above the error, change the IF for this one

If Selection.End = i - 1 And (Selection.End - Selection.Start > 1) Then

That will check if the selected ranges are bigger than one... (this will fix this problem, but if you use suspensive, it will give you an error again because you'll have "..." that is larger than one but still no number).

what im doing is using an integer "j" to store the ascii code of each character

the ascii code for 0 is 48 , the code for 9 is 57 and all the numbers are between them. 46 is for a dot.

HTH
Oct 10 '07 #4
ohhhh ok. well in that case i am still getting an error because i have many ....... in a row in various places.

this is what my document looks like and i want to highlight the number in the middle that are less then .95000 aditionally i want to highlight the number to the right of it and the numbers and text to the left of it as well but that might be too complicated.

42062 ALTA_L98 69.000 0.95212 0.98269
42820 HS_TAP69 69.000 0.93047 0.97650
44400 KARSTN 9 69.000 0.92176 0.97748
42080 ALVIN 9 69.000 0.92959 0.97614
44380 JULIFF 69.000 0.92045 0.98942
44440 MANVEL 9 69.000 0.92236 0.97481

my document also contains all kinds of different characters and symbols like:
-, <, >, $, :, &, etc.
Oct 10 '07 #5
kadghar
1,295 Expert 1GB
ohhhh ok. well in that case i am still getting an error because i have many ....... in a row in various places.

...

my document also contains all kinds of different characters and symbols like:
-, <, >, $, :, &, etc.
Then i think the easiest way to make it work will be making it ignore this errors, since "....." cant be compared, it will never highlight so just ask vb not to tell you that it isnt a number. Add this line before the FOR starts:

on error resume next

Now for the other numbers you wanted to hightlight, give it a try by yourself using selection.start and selection.end

HTH
Oct 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Poster | last post by:
After creating an IN clause from a bunch of character strings created by a Word macro, Query Analyzer complains about a syntax error. The macro takes a column full of character strings and wraps...
0
by: bekil | last post by:
Thanks for your suggestion Murray Jack. I also record macro while doing it manually in word then I edit the macro to see the required code. Firstly I am creating a blank page. Secondly I go to...
16
by: David Ford | last post by:
I have a macro that I use across the board for freeing ram. I'd like to clean up my code so I don't get these warnings. #define sfree(x) _internal_sfree((void **)&x) #define _internal_sfree(x)...
10
by: Brian Kwan | last post by:
Requirement: Call a Word Macro from ASP.NET with parameters Do anyone have idea about this? Please notice the import statement and sample code, as I am a beginner using ASP.NET, thanks for your...
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
2
by: WØCBF | last post by:
I am trying to copy the information from a form into a table. I have tried running the sql code from a macro by using the command : This works and writes the work 'test' into the field name...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
6
by: Eric Layman | last post by:
Hi, I have fields from textareas. With a click of a button, php is able to grab these fields and by using header(), convert the output to Ms Word doc. But the outcome of the word doc...
0
by: Ed from AZ | last post by:
I'm using Word 2003. I use a proprietary Java program that takes all the information in the various forms and generates an XML file. There are times I need to move information between files. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.