Word document from template

  • Thread starter Thread starter Enescu Gabriel
  • Start date Start date
E

Enescu Gabriel

I want to open from excel and VBA a Word instance with a document from word
templates.

I try this:

MyAppID = Shell _
("C:\Program Files\Microsoft Office\Office11\Winword.EXE C:\OFERTA.dot", 1)
AppActivate MyAppID

but this open the template himself not a document based on this template.

Thank you in advance.
Toni
 
Sub nanann(
Dim WrdApp As Word.Applicatio
Dim WrdDoc As Word.Documen

Set WrdApp = CreateObject("Word.Application"
Set WrdDoc = WrdApp.Documents.Add("YourTemplate"
'other operation
WrdDoc.Close SaveChanges:=Fals
WrdApp.Quit
Set WrdDoc = Nothin
Set WrdApp = Nothin
End Su
 
Enescu Gabriel said:
I want to open from excel and VBA a Word instance with a document from word
templates.

I try this:

MyAppID = Shell _
("C:\Program Files\Microsoft Office\Office11\Winword.EXE C:\OFERTA.dot", 1)
AppActivate MyAppID

but this open the template himself not a document based on this template.

Thank you in advance.
Toni

Try the following:

Sub CreateWordDocFromTemplate()
'Excel VBA to create a new Word document from a Word template.
'Requires reference to Microsoft Word n.n Object Library.

Dim wdApp As Word.Application

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = New Word.Application
End If
On Error GoTo 0

wdApp.Visible = True
wdApp.Activate

wdApp.Documents.Add "My Template.dot"

Set wdApp = Nothing

End Sub


the template is located in the default Word templates folder.
 

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

Back
Top