Help With Word Macro

K

kirkm

Recently I had to re-install Windows and Office and a Word macro I
used a lot now fails. I can't figure our why.

Here's the code :

OpenDoc ("D:\file1.html")
Dim D As Document
Set D = ActiveDocument
Dim msg
Dim LastLine%, i%
LastLine = D.Paragraphs.Count
Dim R As Range
For i = 1 To LastLine ' or less while playing
Set R = D.Paragraphs(i).Range
Debug.Print i, R.Words(1).Bold, R.Words(1).Italic,
R.ParagraphFormat.LeftIndent, R
Next
....

This resides in Doc1.doc and previously I could use any
html file in the OpenDoc line, and read it in the i For
Next Loop.

Now, however, lastline is always 1 and the ActiveDocument
is Doc1.doc whereas it should be file1.html.

Any help appreciated.
Thanks - Kirk
 
C

Cindy M.

Hi Kirkm,

"OpenDoc" is not part of the Word object model. I think
what you must have had was:
Documents.Open "D:\file1.html"

And I think it would work best for you like this:
Dim D as Word.Document
Set D = Documents.Open("D:\file1.html")
OpenDoc ("D:\file1.html")
Dim D As Document
Set D = ActiveDocument
Dim msg
Dim LastLine%, i%
LastLine = D.Paragraphs.Count
Dim R As Range
For i = 1 To LastLine ' or less while playing
Set R = D.Paragraphs(i).Range
Debug.Print i, R.Words(1).Bold, R.Words(1).Italic,
R.ParagraphFormat.LeftIndent, R
Next
....

This resides in Doc1.doc and previously I could use any
html file in the OpenDoc line, and read it in the i For
Next Loop.

Now, however, lastline is always 1 and the ActiveDocument
is Doc1.doc whereas it should be file1.html.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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