Error 429 Object required - opening a Word document

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Can't open the Word document even though I give a full path and filename.

Code:
Public Function Merge_2_PDF_Files(strTemplate As String, strFile1 As String, strFile2 As String, Optional strPageFrom As String, Optional strPageTo As String) As Boolean

    Dim WordApp As Object
    Dim WordDoc As Word.Document
    Dim strTemplateFilename As String
    
    On Error Resume Next
        
    Set WordApp = GetObject(, "Word.Application")
    strTemplateFilename = Right(strTemplate, Len(strTemplate) - InStrRev(strTemplate, "\"))
    
    On Error GoTo ErrorHandler
    
    If WordApp Is Nothing Then
        Set WordApp = CreateObject("Word.Application")
        Set WordDoc = WordApp.Documents.Open(strTemplate) 'E R R O R S  H E R E
        WordApp.Visible = True
        If strPageFrom = "" Then
            WordApp.Run "Merge_2_PDF_Files", strFile1, strFile2
        Else
            WordApp.Run "Merge_2_PDF_Files", strFile1, strFile2, strPageFrom, strPageTo
        End If
        WordApp.Quit SaveChanges:=wdDoNotSaveChanges
    Else
        Set WordDoc = WordApp.Documents(strTemplateFilename)
        WordApp.Visible = True
        If strPageFrom = "" Then
            WordApp.Run "Merge_2_PDF_Files", strFile1, strFile2
        Else
            WordApp.Run "Merge_2_PDF_Files", strFile1, strFile2, strPageFrom, strPageTo
        End If
    End If
    
    Set WordApp = Nothing
    
ErrorHandler:
        If Err.Number <> 0 Then
            MsgBox Err.Number & " - " & Err.Description
'            Resume
        End If

End Function
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
My Word file was surrounded by single quotes, hence the error.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,741
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top