Open Word document, modify and Save

D

Dana

Hi All

Is there any way that I can read from a word document in a word-by-word
manner and do my own checks on each word (like a spelling checker), and
modify some words where necessary then save the document again.

Any help is highly appreciated.



Regards


Dana
 
H

Helmut Weber

Hi Dana,

sure.

Dim oWrd As Object
For Each oWrd In ActiveDocument.Range.Words
' what now ?
Next
 
G

Greg

Helmut,

I would have probably started with:

Dim oWord as Word.Range


So I will ask the same question that that fellow Fred has asked. Why
did you use ... As Object?

I would also have clipped that trailing space:
Sub Test()
Dim oWord As Word.Range 'Object
For Each oWord In ActiveDocument.Range.Words
If oWord.Characters.Last = " " Then
oWord.MoveEnd wdCharacter, -1
'Do something like
MsgBox oWord
End If
Next
End Sub
 
H

Helmut Weber

Hi Greg,
Why did you use ... As Object?

Because I didn't know better, but I know now.
I was always wondering about:
paragraph and paragraphs
shape and shapes
section and sections
and why there was a _word_-object missing,
when there was a _words_-object.
I would also have clipped that trailing space

Yes.

The question was a bit too broad for me,
to put much effort into an answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top