Opening a Word Template from within Excel

D

Doctorjones_md

I have the following VBA code with opens a Word Template (.dot extension)
from Excel:

1. CommandButton1 code on worksheet --

Private Sub CommandButton1_Click()
SQLRollup
DeleteBlankRows
RollupToSQLServer1
InsertTrackingSpecificData

frmClients.Show

End Sub

2. Code on frmClients

Private Sub cmdProposal_Click()
frmOrders.Show
frmClients.Hide

End Sub

3. Code on frmOrders

Private Sub cmdManaged_Click()

'opens a new Word Template
Dim wordApp As Word.Application
Dim wordDot As Word.Template
Set wordApp = New Word.Application

On Error Resume Next

With wordApp
.Visible = True
Set wordDot =
..Documents.Open("\\Network\Products\Clients\Orders.dot", , False)
End With


Unload Me

End Sub
==============================================
The problem I'm having is that the code in item#3 opens the template without
forcing a new Document1 -- therefore, the template get over-written by any
modifications made while in use. What's curious is that when I navigate to
the Order.dot file (outside of Excel) and CLICK on it, a Document1 is
created.

How can I modify the code to do (from within Excel) what simply openning the
file from Explorer does?

Thanks in advance for any and all suggestions/recommendations.
 
T

Tony Jollans

The template opens because that's what you have coded ...

documents.OPEN(etc.....

What you want to do is add a new document based on the template ...

documnets.ADD("whatever.dot", ....

Clicking on a document (.doc file) or template (.dot file) or any other file
type causes the default action for that file type to be invoked. The default
for documents is "Open"; the default for templates is "New" (i.e. create a
new document based on the template)
 
D

Doctorjones_md

Tony -- thanks for the quick reply ...

I'd already tried the following (Word application opened, but the document
(Order.dot) didn't -- any ideas as to why?

Private Sub cmdManaged_Click()

'opens a new Word Template
Dim wordApp As Word.Application
Dim wordDot As Word.Template
Set wordApp = New Word.Application

On Error Resume Next

With wordApp
.Visible = True
Set wordDot =
.Documents.Open("\\Network\Products\Clients\Orders.dot", , False)

End With

Unload Me

End Sub
 
T

Tony Jollans

Who knows? Netwrok issue perhaps. Try running without "On Error Resume Next"
and see what error you get.
 
E

Ed

From the Word VBA Help file for "Add Method":

Add method as it applies to the Documents object.
Returns a Document object that represents a new, empty document added to the
collection of open documents.

expression.Add(Template, NewTemplate, DocumentType, Visible)

expression Required. An expression that returns a Documents object.

Template Optional Variant. The name of the template to be used for the new
document. If this argument is omitted, the Normal template is used.

NewTemplate Optional Variant. True to open the document as a template. The
default value is False.

DocumentType Optional Variant. Can be one of the following
WdNewDocumentType constants: wdNewBlankDocument, wdNewEmailMessage,
wdNewFrameset, or wdNewWebPage. The default constant is wdNewBlankDocument.

Visible Optional Variant. True to open the document in a visible window.
If this value is False, Microsoft Word opens the document but sets the
Visible property of the document window to False. The default value is True.

This example creates a new document based on the Professional Memo template.

Documents.Add Template:="C:\Program Files\Microsoft Office" _
& "\Templates\Memos\Professional Memo.dot"I think what you want is
something like:> With wordApp> .Visible = True> Set wordDot =>
..Documents.Add(Template:=""\\Network\Products\Clients\Orders.dot")(which is
what Tony suggested in his first response).Ed"Doctorjones_md"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top