Log in

View Full Version : OPening a doc with bookmarks.



dotolee
12-24-2007, 12:37 PM
When i try to create a bookmarks object, the system crashes with an error: "429 Activex component can't create object." I've bolded the line that's crashing... any suggestions?

Private Sub command1_Click()
On Error GoTo Err_Handler
Dim wdApp As Object 'Word.Application
Dim wdDoc As Object 'Word.Document
Dim blnError As Boolean
Dim blnNewApp As Boolean
Dim strTemplate As String
Dim bookmarks As Object ' Word.bookmarks
Dim bookmark As Object ' word.bookmark
strTemplate = "C:\Development\UHN\Aviva\consorttemplate1.dot"
If Len(strTemplate) > 0 Then
If Len(Dir(strTemplate)) > 0 Then
' The template exists
Else
MsgBox "The template does not exist", vbExclamation
Exit Sub
End If
Else
MsgBox "First select a template", vbInformation
Exit Sub
End If
' Switch off normal error handling as we attempt to use ruuning instance
' of Word. If Word is not running, we try to start an instance
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set wdApp = CreateObject("Word.Application")
If Err.Number <> 0 Then
blnError = True
MsgBox "Error starting Word", vbCritical, "Error"
GoTo Exit_Handler
Exit Sub
Else
blnNewApp = True
End If
End If
' Switch normal error handling back on
On Error GoTo Err_Handler
Set wdDoc = wdApp.Documents.Add(strTemplate)
Set bookmarks = CreateObject("Word.Bookmarks")
If Err.Number <> 0 Then
blnError = True
MsgBox "Error starting Word", vbCritical, "Error"
GoTo Exit_Handler
Exit Sub
Else
Set bookmark = CreateObject("Word.bookmark")
End If
' set a bookmark as a test.
wdDoc.bookmarks.Item("eligibleTotal").Range.Text() = 56
wdApp.Visible = True
wdApp.WindowState = 1
wdApp.Browser.Target = 1
Application.Echo True, ""
wdApp.Activate
wdDoc.Activate
Exit_Handler:
If Not wdDoc Is Nothing Then
Set wdDoc = Nothing
End If
If Not wdApp Is Nothing Then
If blnError And blnNewApp Then
wdApp.Quit
End If
Set wdApp = Nothing
End If
Exit Sub
Err_Handler:
DoCmd.Hourglass False
blnError = True
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub