Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting chars in Word

Status
Not open for further replies.

dbaseboy

Programmer
Apr 24, 2002
48
GB
Im trying to write a module that will amend every 524th and 525th chars.

ie I have files that are Fixed Length (525 byte record lengths) but require Control Chars at end of each record to read into Access. I therefore want to take a file in Word and go to the 524th char, select it and the 525th and replace the spaces with a Line Feed. Then move a further 524 chars and do it again until end of file.

Ive sussed the selecting and replacing but cant seem to find the command (if it exists) to select a certain number of chars.

Any ideas my very clever mates?
 
try this to move the cursor to the beginning of the file:

Selection.HomeKey Unit:=wdStory

to move your cursor 524 time to the left:

Selection.MoveLeft Unit:=wdCharacter, Count:=523

note: This puts you at the beginning of Character 524

to highlight final 2 spaces

Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend

to overwrite the selected text with a line feed

Selection.TypeText Text:=Chr(10)


I haven't tried this code myself, but I think it will work.

Cheers,
NoChoice
 
Hi dbaseboy,

You shouldn't need to Select at all, just work with the text something like ..

Code:
For Pos = ActiveDocument.Range.End To 2 Step -525
    ActiveDocument.Range(Pos - 2, Pos).Text = vbLf
Next

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top