Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2012, 08:35 AM
tinfanide tinfanide is offline VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) Windows 7 64bit VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) Office 2010 32bit
Expert
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error))
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default VBA in Excel: Add a new Word Document on Template (Type Mismatch Error))

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.
Reply With Quote
  #2  
Old 03-29-2012, 09:10 AM
tinfanide tinfanide is offline VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) Windows 7 64bit VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) Office 2010 32bit
Expert
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error))
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Self-solved.

Code:
Dim oDoc As Word.Document ''' not Word.Documents
Code:
Word.Documents
is different from
Code:
Word.Document
.
Even though I don't know how it's different from the other one.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) 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
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) Document template import in Word 2011 Mac monrepos Word 1 05-09-2011 03:41 PM
VBA in Excel: Add a new Word Document on Template (Type Mismatch Error)) 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:47 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft