Discussion:
Open Word document, modify and Save
(too old to reply)
Dana
2006-01-24 12:38:12 UTC
Permalink
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
Helmut Weber
2006-01-24 13:40:02 UTC
Permalink
Hi Dana,

sure.

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

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Dana
2006-01-24 15:15:24 UTC
Permalink
Thanks

I think that is what I want.



Regards
Post by Helmut Weber
Hi Dana,
sure.
Dim oWrd As Object
For Each oWrd In ActiveDocument.Range.Words
' what now ?
Next
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Greg
2006-01-24 17:58:56 UTC
Permalink
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
Helmut Weber
2006-01-25 08:52:13 UTC
Permalink
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.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Greg Maxey
2006-01-25 11:13:25 UTC
Permalink
Helmut,

I share your point about it being a broad question.

Cheers.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Post by Helmut Weber
Hi Greg,
Why did you use ... As Object?
Because I didn't know better, but I know now.
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.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Loading...