Saving a Word document after bookmarks are filled

S

Stanley

I have the following code:
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open C:\TestDoc.doc")

With objWord
.ActiveDocument.Bookmarks("directions").Select
.Selection.Text = "my directions"
.ActiveDocument.Bookmarks("DSO").Select
.Selection.Text = "DSO"
End With

objWord.ActiveDocument.PrintOut Copies:="1", Background:=False
objWord.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
objWord.Quit
Set objWord = Nothing

I don't save changes to my documents because they would ruin my book marks.
What I would like to do is do a save as to get a copy of the document some
where and then not Save Changes to preserve my documents with its bookmarks.
Thanks,
Stanley
 
D

Doug Robbins - Word MVP

You should save C:\TestDoc as a template so that it has the .dot extension
and then use

Dim objWord As Word.Application
Dim WordDoc as Word.Document
Set objWord = CreateObject("Word.Application")
Set WordDoc = objWord.Documents.Add "C:\TestDoc.dot" 'Create a new document
from the template

With WordDoc
.Bookmarks("directions").Range.InsertBefore "my directions"
.Bookmarks("DSO").Range.InsertBefore "DSO"
.PrintOut Copies:="1", Background:=False
.Close savechanges:=wdDoNotSaveChanges
End With

Set WordDoc = Nothing
objWord.Quit
Set objWord = Nothing

Then your template (C:\TestDoc.dot") will remain intact for further use.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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

Top