I am automating Word from VB.Net.
I open a document by:
Dim msWord as Word.Application = CreateObject("Word.Application")
Dim doc As Word.Document = msWord.Documents.Add(Template:=Path)
where path points to a template file I created with a header and a watermark. The template has some bookmarks which I want to dynamically set to some appropriate text values:
doc.Bookmarks("DocumentTitle").Range.Text = "The Joy of Office Automation"
If I comment out that line, the document opens in Word with the watermark, etc, in place. If I let that line execute, it inserts the text as appropriate, but the watermark and other things disappear from the document. You can actually see it flash briefly, and then disappear.
FWIW, this is Office Word 2007, and I am opening a .Dot (Word 97-2003) template. The Bookmark.Range.Text I am setting is in the document header.
Office Automation gurus, what am I doing wrong?
Thanks, Gerald