Expert's advice reqd: Opening word via Excel code

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

Guest

I am opening a word document from Excel VBA code ... The word doucment is a mail merge document linked to another excel fil

I use the follwoing code
dim docpath as strin
docpath = "C:\MailMerge\MailMerge.doc
On error resume nex

dim wd as objec
set wd = Getobject(,"Word.Application") ' If word is not running this will generate an erro

if err.number <> 0 then ' word is running otherwise word is not runnin
msgbox err.number & "-" & err.descriptio
' this if statement is only for debuggin
endi

if wd is Nothing the
set wd = "Word.Application
EndI

wd.Application.Documents.Open Filename:=docpath, Readonly:= Tru

The problem is: It takes about 30 - 40 seconds to open the word document through VBA code where as If I just double click the word file in explorer it just take 3-5 seconds

How can I improve the speed when I open the word file through VBA code

Any help would be appreciated.
 
Here is one I use that works. Don't remember where I got it.
Sub openxmas()
Dim appWD As Object
Dim wdDoc As Document
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
appWD.ChangeFileOpenDirectory ActiveWorkbook.Path
appWD.Documents.Open Filename:="XmasListEnvelopes.doc"
Set wdDoc = appWD.ActiveDocument
End Sub
so, it appears that
set wd = Getobject(,"Word.Application") '
needs to be
set wd = createobject("Word.Application") '
--
Don Guillett
SalesAid Software
(e-mail address removed)
Mohan said:
I am opening a word document from Excel VBA code ... The word doucment is
a mail merge document linked to another excel file
I use the follwoing code:
dim docpath as string
docpath = "C:\MailMerge\MailMerge.doc"
On error resume next


dim wd as object
set wd = Getobject(,"Word.Application") ' If word is not running this will generate an error

if err.number <> 0 then ' word is running otherwise word is not running
msgbox err.number & "-" & err.description
' this if statement is only for debugging
endif

if wd is Nothing then
set wd = "Word.Application"
EndIf

wd.Application.Documents.Open Filename:=docpath, Readonly:= True

The problem is: It takes about 30 - 40 seconds to open the word document
through VBA code where as If I just double click the word file in explorer
it just take 3-5 seconds.
 

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