HELP: active X component can't create object

P

patskinny

I have the code below which opens a word template and then populates
the form. Sometimes it works no problem and other times I get a
"runtime error" 429 stating "active X component can't create object".
Anyone have insight into the inconsistency?

thank you!!!


below is the code:


Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim prps As Object
Dim strDate As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File
Dim strTemplate As String
Dim strTemplatePath As String
Dim strTemplateNameAndPath As String
Dim doc As Word.Document
Dim strTitle As String
Dim strPrompt As String


Set appWord = GetObject(, "Word.Application")
strTemplatePath = appWord.Options.DefaultFilePath
(wdUserTemplatesPath)
Debug.Print "Template path: " & strTemplatePath
strTemplatePath = "B:\CSITE 3.0\Supporting Source Files\word
templates\"
strLetter = "AdminReport.dot"
strTemplateNameAndPath = strTemplatePath & strLetter
Debug.Print "Template and path: " & strTemplateNameAndPath


Set fil = fso.GetFile(strTemplateNameAndPath)
If fil Is Nothing Then
strPrompt = "Can't find " & strLetter & " in " _
& strTemplatePath & "; canceling"
MsgBox strPrompt, vbCritical + vbOKOnly
GoTo ErrorHandlerExit
End If


Set docs = appWord.Documents
Set doc = docs.Add(strTemplateNameAndPath)


Set prps = doc.CustomDocumentProperties


With prps
.Item("Score").Value = Nz(Me![AdminScore])
.Item("Port").Value = Nz(Me![PortName])
.Item("EvalMonth").Value = Nz(Me![EvalPeriod])
.Item("Q1").Value = Nz(Me![cboAdmin1])
.Item("Q2").Value = Nz(Me![cboAdmin2])
.Item("Q3").Value = Nz(Me![cboAdmin3])
.Item("Q4").Value = Nz(Me![cboAdmin4])
.Item("Q5").Value = Nz(Me![cboAdmin5])


End With


With appWord
.Visible = True
.Activate
.Selection.WholeStory
.Selection.Fields.Update
.Selection.MoveDown Unit:=wdLine, Count:=1
End With
 
D

Douglas J. Steele

What line of code raises the error?

I'm guessing it's

Set appWord = GetObject(, "Word.Application")

and you don't already have Word open. When Word isn't already open, you need
to use

Set appWord = CreateObject("Word.Application")
 

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