Duplicate document on memory... is it possible (VBA, Word 2010 Macro)
-
Hello, I would like to make a duplicate of the currently open document via a VBA macro. That is, when running the macro, it will use the current active document as source and make a copy of it without saving it to a file. The current document may be modified (changes were not yet saved to a file), and it could be based on a specific template, with headers/footers/fields. The new copy, should have an identical content (including headers/footers/fields) as the original, based on the same template but with a new name and not saved to a file yet. (The user may save it later if required) Is this possible? Thanks in advance.
-- **Ricky Marek** (_AKA: rbid_)
-- "Things are only impossible until they are not" --- Jean-Luc Picard My articles -
Hello, I would like to make a duplicate of the currently open document via a VBA macro. That is, when running the macro, it will use the current active document as source and make a copy of it without saving it to a file. The current document may be modified (changes were not yet saved to a file), and it could be based on a specific template, with headers/footers/fields. The new copy, should have an identical content (including headers/footers/fields) as the original, based on the same template but with a new name and not saved to a file yet. (The user may save it later if required) Is this possible? Thanks in advance.
-- **Ricky Marek** (_AKA: rbid_)
-- "Things are only impossible until they are not" --- Jean-Luc Picard My articlesPerhaps something like this will work for you.
Sub CopyDoc()
' save a reference to the source document
Dim sourcedoc As Document
Set sourcedoc = Application.ActiveDocument' create a new document with the same template as the source document Dim newdoc As Document Set newdoc = Application.Documents.Add(Template:=sourcedoc.AttachedTemplate.FullName, Visible:=True) ' copy sourcedoc and paste in newdoc sourcedoc.Range.Copy newdoc.Range.Paste sourcedoc.Activate Set sourcedoc = Nothing Set newdoc = Nothing
End Sub