Open word template file

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234
Morning all,

I'm having some trouble with trying to get a template file to open from an excel link.

I have a word document template, which is basically a blank quote sheet. I want this document to open, but if I use a hyperlink it doesn't create a copy like a template normally would, but you end up editing the actual template.

So, I think that I need a macro here, but am really clueless as to what to do. I've had a good search but have just been confused, so any help would be much appreciated.

Thanks in advance,

dirtychinchilla
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

bewsh1987

Board Regular
Joined
Sep 3, 2013
Messages
232
add a command button to your sheet and add the following code


try

Code:
Private Sub CommandButton1_Click()
Set word = CreateObject("word.Application")
word.documents.Open "c:\filelocation\filename.doc"
word.Visible = True
End Sub

or for new document

try
Code:
Private Sub CommandButton1_Click()
Set word = CreateObject("word.Application")
word.Visible = True
With word
.Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
End With
End Sub
 
Last edited:

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234
Hi bewsh, thanks for your reply.

The second code is no good for me as that does not use an existing document, but I appreciate you showing me so I can get a feel for it.

The first code - it works in the sense that it opens a document, but it generates a message saying that the document is already open, so do I want to open a read only copy etc. The document, however, is not open and is not being used by anyone else.

Thanks again,

dirtychinchilla
 

bewsh1987

Board Regular
Joined
Sep 3, 2013
Messages
232
no problem

I get the same problem if the document is already open

if you need the document open readonly

try

Code:
Private Sub CommandButton1_Click()
Set word = CreateObject("word.Application")
word.documents.Open "c:\filelocation\filename.doc", Readonly:= true
word.Visible = True
End Sub
 

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234

ADVERTISEMENT

Hmm OK, I get what that does, but it doesn't really open the template in the manner that it's supposed to function (hopefully this makes sense).
 

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234

ADVERTISEMENT

No, I want to open a template document as if you'd just double clicked the icon, which opens a copy...
 

bewsh1987

Board Regular
Joined
Sep 3, 2013
Messages
232
We will get there. I just hope am understanding you correctly :). sometimes I misread things

three different codes below

I have left the file location as it would look on my Pc. you may want to change them

Code:
Private Sub CommandButton1_Click()
'new template
Set word = CreateObject("word.Application")
word.Documents.Add Template:= _
        "C:\Users\ian.bushell\AppData\Roaming\Microsoft\Templates\Normal.dotm", _
        NewTemplate:=True, DocumentType:=0
word.Visible = True
End Sub

Private Sub CommandButton2_Click()
'existing file as New template
Set word = CreateObject("word.Application")
word.Documents.Add Template:= _
        "S:\Cosmetics Merchandise Planning\Ian\SQL Queries.doc", _
        NewTemplate:=true, DocumentType:=0
word.Visible = True
End Sub

Private Sub CommandButton3_Click()
'existing file as new document
Set word = CreateObject("word.Application")
word.Documents.Add Template:= _
        "S:\Cosmetics Merchandise Planning\Ian\SQL Queries.doc", _
        NewTemplate:=False, DocumentType:=0
word.Visible = True
End Sub
 
Last edited:

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234
Sir, they all work perfectly, thank you very much!! The only bit I can't get my head around is that the file has renamed itself to "Template1"
 

bewsh1987

Board Regular
Joined
Sep 3, 2013
Messages
232
ah I think I get it.

if you have this document open it will always open as readonly

I have set the location of the file to open as a template hence template1

you can code it in to save as new name ( if the same name will try to save over the original)

options
open same file as read only (unless its closed)
open same file as new document (document 1)
open same file as new Template (Template 1)

the only option is to manually save them as new name ( can give you code to save file as different name every time)

I hope am getting somewhere now
 

Forum statistics

Threads
1,137,293
Messages
5,680,651
Members
419,923
Latest member
Kalthus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top