Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2007

Tip: Looking for answers? Try searching our database.

Opening a Word Template from within Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doctorjones_md - 25 Jan 2007 17:43 GMT
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.
Tony Jollans - 25 Jan 2007 18:07 GMT
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)

Signature

Enjoy,
Tony

>I have the following VBA code with opens a Word Template (.dot extension)
>from Excel:
[quoted text clipped - 50 lines]
>
> Thanks in advance for any and all suggestions/recommendations.
Doctorjones_md - 25 Jan 2007 18:18 GMT
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

> The template opens because that's what you have coded ...
>
[quoted text clipped - 63 lines]
>>
>> Thanks in advance for any and all suggestions/recommendations.
Tony Jollans - 25 Jan 2007 18:25 GMT
Who knows? Netwrok issue perhaps. Try running without "On Error Resume Next"
and see what error you get.

Signature

Enjoy,
Tony

> Tony -- thanks for the quick reply ...
>
[quoted text clipped - 88 lines]
>>>
>>> Thanks in advance for any and all suggestions/recommendations.
Ed - 25 Jan 2007 20:19 GMT
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
> Tony -- thanks for the quick reply ...
>
[quoted text clipped - 88 lines]
>>>
>>> Thanks in advance for any and all suggestions/recommendations.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.