Hi, I have a spreadsheet that is populated with data.
Each column has a header and there can be many rows.
I want to copy/export a selected row of data to a Word Template,
Save the Word file as Filename.Doc
Close trhe Word Application
and then return to Excel (Command Button that calls the code).
I found this example and thought it would/might work:
Option Explicit
Sub ReplaceText()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Add(Template:="D:SEARS SOLAR Template - CSR", NewTemplate:=False, DocumentType:=0)
With wDoc
.Application.Selection.Find.text = "<<Customer Name>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A5")
.Application.Selection.EndOf
.Application.Selection.Find.text = "<<dob>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A6")
.ActiveDocument.SaveAs Filename:="C:\Documents\NewWordDocumentFromTemplate.doc"
End With
End Sub
This code fails at the first DIM Statement so I can't do any testing/experimenting to try and make it work.
Am I on the right/wrong track?
Your help will be greatly appreciated
Each column has a header and there can be many rows.
I want to copy/export a selected row of data to a Word Template,
Save the Word file as Filename.Doc
Close trhe Word Application
and then return to Excel (Command Button that calls the code).
I found this example and thought it would/might work:
Option Explicit
Sub ReplaceText()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Add(Template:="D:SEARS SOLAR Template - CSR", NewTemplate:=False, DocumentType:=0)
With wDoc
.Application.Selection.Find.text = "<<Customer Name>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A5")
.Application.Selection.EndOf
.Application.Selection.Find.text = "<<dob>>"
.Application.Selection.Find.Execute
.Application.Selection = Range("A6")
.ActiveDocument.SaveAs Filename:="C:\Documents\NewWordDocumentFromTemplate.doc"
End With
End Sub
This code fails at the first DIM Statement so I can't do any testing/experimenting to try and make it work.
Am I on the right/wrong track?
Your help will be greatly appreciated