close old document macro

S

schmidty169

I have a form that saves the file using the value from a
variable as the name. Now I want to be able to open
(already have that working) a new doc based on a .dot I
want to then close the previous file. I don't know how to
pass the variable value onto the close command here is
what I have so far

Documents.Add Template:= _
"\\Server\Share\forms\templates\Full page
Scans2.dot", NewTemplate:= _
False, DocumentType:=0
Windows(ActiveDocument.FormFields
("Text1").Result).Activate
ActiveDocument.Close
End Sub
 
M

martinique

ActiveDocument is a shortcut reference to one member of the Documents
collection. In its place you can use any document reference. There are
several methods:

Dim pDocument as Word.Document
set pDocument = ActiveDocument [This 'remembers' the ActiveDocument at the
time]
:
Documents.Add .... [this changes the ActiveDocument, but not pDocument]
:
pDocument.Close


or you can refer to the members of the Documents() collection by name:

Dim pName as string
pName = ActiveDocument.Name
:
Documents(pName).Close

(But remember that the name changes if you SaveAs)
 

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