ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Word document from template (https://www.excelbanter.com/excel-programming/294717-word-document-template.html)

Enescu Gabriel

Word document from template
 
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



losmac[_2_]

Word document from template
 
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


John Williams[_4_]

Word document from template
 
"Enescu Gabriel" wrote in message ...
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.


All times are GMT +1. The time now is 11:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com