It's really quite simple ...
This sample opens a Word template, uses Find & Replace to change the
content of the document and then saves the document. Hope it helps.
Regards
James
Add the reference to the version of MS Word you are using. Then in the
code behind page ...
Dim MSWord As New Word.ApplicationClass
Dim doc As New Word.DocumentClass
strFile = Server.MapPath("/template.dot")
MSWord = CreateObject("Word.Application")
MSWord.Visible = True
doc = MSWord.Documents.Add(strFile)
selection = MSWord.Selection
MSWord.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument
strFind = "<date>"
strReplace = Format(DateValue(Now()), "D")
SearchAndReplace(strFind, strReplace)
strFind = "<name>"
strReplace = theName
SearchAndReplace(strFind, strReplace)
strFind = "<address>"
strReplace = address
SearchAndReplace(strFind, strReplace)
strFile = Server.MapPath("") & "filename.doc"
doc.SaveAs(strFile)
doc.Close()
doc = Nothing
MSWord.Quit()
MSWord = Nothing
end sub
Function SearchAndReplace(ByVal strTmpSearchFor, ByVal
strTmpReplaceWith)
selection.Find.ClearFormatting()
selection.Find.Replacement.ClearFormatting()
selection.Find.Text = strTmpSearchFor
selection.Find.Replacement.Text = strTmpReplaceWith
selection.Find.Forward = True
selection.Find.Wrap = Word.WdFindWrap.wdFindContinue
selection.Find.Format = False
selection.Find.MatchCase = False
selection.Find.MatchWholeWord = False
selection.Find.MatchWildcards = False
selection.Find.MatchSoundsLike = False
selection.Find.MatchAllWordForms = False
selection.Find.Execute(, , , , , , , , , ,
Word.WdReplace.wdReplaceAll)
End Function