How to create a copy of an open document
Article contributed by Ibby
If your current document has been saved at least once, the following will:
- create a new document that is an exact copy of the current document – it will include any modifications that have not yet been saved.
- prompt you for a location and filename to save this copy (you can hardcode the path and filename if you like)
- close this copy
All this occurs without saving the current document.
Dim myCopy
As Document
Dim docName As String
' Retrieve name of ActiveDocument
docName = ActiveDocument.Name
' Test if Activedocument has previously been saved
If ActiveDocument.Path = ""
Then
' If not previously saved
MsgBox "The current document must be saves at least
once."
Else
' If previously saved, create a copy
Set myCopy =
Documents.Add(ActiveDocument.FullName)
' Show SaveAs dialog to allow user to
save copy
With
Dialogs(wdDialogFileSaveAs)
' Set name in
SaveAs dialog
.Name = "Copy_of_" & docName
.Show
End With
' Close copy
myCopy.Close
End If
See also:
How to copy an open file using VBA
Useful WordBasic commands that have no VBA
equivalent