creating word doc from a word template by macro

M

MarkC

Can anyone help please, I have an excel spreadheet that when a cell is
controlled by a Y or N answer only, it selects a word document to complete.
This form shoudl be created from a template in the normal way word does, but
my macro is simply opening the template (.dot file openining, not a .doc
file), not creating from the template. Can anyone help as to how I can
achive this by modifying the VBA below.

Sub GetWordDocument()
Dim oWordApp As Object
Dim oDoc As Object
Dim sFilename As String

Set oWordApp = CreateObject("Word.Application")
If Range("G3").Value = "Y" Then
sFilename = "M:\001_Quality\Manual advice Notes\Template\ST011AFO
Issue 1 Advice note AND Customs invoice.dot"
Else
sFilename = "M:\001_Quality\Manual advice Notes\Template\ST011FO
Issue 4 Manual Advice Note.dot"
End If
Set oDoc = oWordApp.Documents.Open(sFilename)
oWordApp.Visible = True
Set oDoc = Nothing
Set oWordApp = Nothing
End Sub


Private Sub CommandButton1_Click()

End Sub


thank you
 
J

Jean-Guy Marcil

MarkC was telling us:
MarkC nous racontait que :
Can anyone help please, I have an excel spreadheet that when a cell is
controlled by a Y or N answer only, it selects a word document to
complete. This form shoudl be created from a template in the normal
way word does, but my macro is simply opening the template (.dot file
openining, not a .doc file), not creating from the template. Can
anyone help as to how I can achive this by modifying the VBA below.

Sub GetWordDocument()
Dim oWordApp As Object
Dim oDoc As Object
Dim sFilename As String

Set oWordApp = CreateObject("Word.Application")
If Range("G3").Value = "Y" Then
sFilename = "M:\001_Quality\Manual advice
Notes\Template\ST011AFO Issue 1 Advice note AND Customs invoice.dot"
Else
sFilename = "M:\001_Quality\Manual advice
Notes\Template\ST011FO Issue 4 Manual Advice Note.dot"
End If
Set oDoc = oWordApp.Documents.Open(sFilename)
oWordApp.Visible = True
Set oDoc = Nothing
Set oWordApp = Nothing
End Sub


Private Sub CommandButton1_Click()

End Sub


thank you

Change

Set oDoc = oWordApp.Documents.Open(sFilename)

to

Set oDoc = oWordApp.Documents.Add(sFilename)



--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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