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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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).
 
Upvote 0
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:
Upvote 0
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"
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,809
Members
449,048
Latest member
greyangel23

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
Back
Top