How to select a character of text

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Novice (6tc1ATqlinkDOTqueensuDOTca)
Date: 03/12/04


Date: Fri, 12 Mar 2004 07:31:14 -0800

Hi all, I previously posted a fairly long request (see below). However, for now I would be happy to just learn how to select a single character of text (in MS Word 2000) and check what it is equal to.

For example, let's say I have a microsoft word document containing the sentence:
This is a sentence in Microsoft Word.

How can I write a VBA script that will check a character of the sentence and see if it is equal to, say the letter "n". Eventually I would like to make this into a looping structure that checks every character, but for now I would be happy with just getting the VBA to do a character equivalence test.

I have some VBA experience in Excel, but using Workbooks, Worksheets and cells is a bit different then scanning the text in Word.

Also please feel free to direct me to a decent online (free) VBA for Word tutorial.

Thanks,
Novice
---------------------PREVIOUS POST---------------------
Hi all, I'm relatively new to VBA (never used it in word before) but I
have the following visual basic code that almost does what I want (by
the way I'm using Word 2000):
  Selection.MoveRight Unit:=wdCharacter, Count:=1
  Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
  Selection.Cut
  Selection.MoveLeft Unit:=wdCharacter, Count:=1
  Selection.Paste
  Selection.MoveDown Unit:=wdLine, Count:=1

However, I want to only select text that is either a number (0, 1, 2,
3, 4, 5, 6, 7, 8 or 9) or a period ("."). Then once it reaches a
section of text that is neither a number nor a period, I want that to
be assigned to the "Count" variable above.

If I could have that - that would be grand.

However, beyond that - if I could get it to continue iterating down
the document until there are no more fields to:
1. move right
2. highlight across only numbers and periods
3. cut that
4. move left
5. past that
6. then move down again

If on the sixth step it reaches the bottom of the document I would
like the Sub to stop.

Thanks for any advice,
Novice


Quantcast