VB counting word in MS WORD - problem ?

  • Thread starter Thread starter Garry
  • Start date Start date
G

Garry

I have written a VB program to could the number of words in a Microsoft word
document.

The program works fine on development pc's, but when I installed on a test
machine, it crashes.

In VB, I am including Microsoft word 11.0 object library.

The VB prorgam is :

dim wordapp as new word.application
dim worddoc as new word.document

set worddoc=wordapp.documents.open (MyfileName, , True)

display (worddoc.Words.count-1)

It crashs on the set line.

Any ideas please.

thanks

Garry
 
Hi Garry,

The following works fine for me:

Dim wordapp As New Word.Application
Dim worddoc As New Word.Document
Set worddoc = wordapp.Documents.Open("D:\Documents\04test.doc", , True)
MsgBox worddoc.Words.Count - 1

Are you sure that MyfileName is loaded with a valid path\filename.

Note that Display does not work.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
Back
Top