![]() |
|
|
|
#1
|
|||
|
|||
|
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
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. |
|
#2
|
|||
|
|||
|
Self-solved.
Code:
Dim oDoc As Word.Document ''' not Word.Documents Code:
Word.Documents Code:
Word.Document Even though I don't know how it's different from the other one. |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248
|
Joe Patrick | Word VBA | 2 | 01-30-2012 07:23 AM |
Document template import in Word 2011 Mac
|
monrepos | Word | 1 | 05-09-2011 03:41 PM |
Word - Links point to template rather than new document
|
mconigol | Word | 1 | 04-01-2011 03:29 PM |
| Book type template for ppt | pengyou | PowerPoint | 0 | 12-04-2009 12:56 AM |
| How to type on the back of word template receipts through word ??? | Qintex Solutions llc | Word | 3 | 10-02-2009 07:52 AM |