Add a new document on an existing template in Excel
Module1:
Code:
Public Sub temp()
''' Early binding
Dim oWord As Word.Application
Set oWord = New Word.Application
oWord.Visible = True
Dim fName As String
fName = "C:\Users\Tin\Desktop\temp1.dotx"
Dim oDoc As Word.Documents
Set oDoc = oWord.Documents.Add(fName) ''' Error: Type Mismatch
''' Late binding NO ERROR
'Dim oWord As Object
'Set oWord = CreateObject("Word.Application")
'oWord.Visible = True
'Dim oDoc As Object
'Dim fName As String
'fName = "C:\Users\Tin\Desktop\temp1.dotx"
'Set oDoc = oWord.Documents.Add(fName)
oDoc.Close
oWord.Quit
Set oDoc = Nothing
Set oWord = Nothing
End Sub
Please see the comments.
I don't know why in early binding adding a new doc on a template causes the type mismatch error, but not in late binding.