Word Object Library - Slow on some machines

N

Norrie

Hello, I am hoping that someone can solve a problem for me...

I have written a piece of VB code that uses the "Word Object Library" and is
designed to go through each word in the documents range to create a profile
of all words used within a specified document. Below is a stripped down
version of the code used:

Public Sub ProcessDocument(sFileName As String)
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oSection As Word.Section, oRange As Word.Range
Dim sDocumentWords(1000) As String
Dim iWordCounter As Integer

Set oWord = New Word.Application
Set oDoc = oWord.Documents.Open(sDocumentPath)

For Each oSection In .Sections
For Each oParagraph In oSection.Range.Paragraphs
Set oRange = oParagraph.Range
For iCounter = 1 To oRange.Words.Count
iWordCounter = iWordCounter + 1
sDocumentWords(iWordCounter) =
oRange.Words(iCounter).Text
Next iCounter
Next oParagraph
Next oSection

oDoc.Close
oWord.Quit

Set oDoc = Nothing
Set oWord = Nothing
Exit Sub


The problem that I am experiencing is that this code will execute (fairly)
quickly on most machines, but on my own machine it seems to run very slowly.
(When tracing throught the code in VB using F8 to step through the code, each
line will take 1-2 secs to execute before going to next line)

I have also noticed that if I launch Word manually from my desktop whilst
the VB code is processing a document, that the VB code instantly speeds up to
the speed that i expect.

Any help in this matter will be gratefully received.
 

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