azizrasul
Well-known Member
- Joined
- Jul 7, 2003
- Messages
- 1,304
- Office Version
- 365
- 2019
- 2016
- Platform
- 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