Word Automation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using Visual basic 6.0 and Office 2000 to generate letters. Creating the
letters from the VB6.0 using Word Automation. It was creating the letter
without any problem before. After when i installed Windows XP SP2 the letter
generation process is very slow. Could you please tell me what the exact
problem is.
 
'Exact problem' !? On the information provided you'll be lucky to get even
vague advice. What part of the process is causing the delays?
 
"Generally" you are passing calls to Word across the OLE divide.

Each of those calls is being validated and re-evaluated, and each piece of
code you hand to Word is being recompiled on each call.

It's a notoriously inefficient way to run.

Re-compile your program as a macro in VBA and run as much as possible from
within Word itself. Take care to re-use your objects when you can, and
destroy them when you no longer need them.

You will get two orders of magnitude higher performance.

Cheers


'Exact problem' !? On the information provided you'll be lucky to get even
vague advice. What part of the process is causing the delays?

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
That's exactly the opposite of my experience. I had a whole bunch of macros
that I subsequently ported to VB and compiled as a DLL, which gets called
from my menu in Word. *Much* faster than the macro versions (plus all the
benefits of VB over VBA).
 
I ran the below program in a machine with XP SP1 and Word 2000 it took only 2
or 3 seconds to insert the bookmarks into the word document. But in a machine
with XP SP2 and Word 2000 it took 18 seconds in an average. I am using the
similar kind of program to insert the bookmarks into a letter at the runtime.

Could anyone please help me out.

Private Sub Command1_Click()
On Error GoTo err
Dim obj As New Word.Application
Dim bk As Bookmark
obj.Documents.Open "C:\Test\ObjA.dot"
obj.Visible = True
StartLog
SendToLog ("BookMark Insertion Starts")
For Each bk In obj.ActiveDocument.Bookmarks
If obj.ActiveDocument.Bookmarks.Exists(bk.Name) Then
obj.ActiveDocument.GoTo What:=wdGoToBookmark, Name:=bk.Name
obj.ActiveDocument.Bookmarks(bk.Name).Select
obj.Selection.InsertAfter bk.Name
obj.ActiveDocument.Bookmarks(bk.Name).Delete
End If
Next
SendToLog ("BookMark Insertion Ends")
EndLog
MsgBox "completed"

err:
Set obj = Nothing

End Sub
 

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

Back
Top