Clone current active document without saving to a file, is this possible?

Discussion in 'Word VBA' started by Ricky Marek, Oct 18, 2013.

  1. Ricky Marek

    Ricky Marek Guest

    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.
     
    Ricky Marek, Oct 18, 2013
    #1
    1. Advertisements

  2. Ricky Marek

    Stefan Blom Guest

    You can use Documents.Add with the name of the current document as the
    "template name." The requirement is that the current document has been saved
    to disk. For example:

    Sub CreateNewDocBasedOnCurrentDoc()
    If Documents.Count < 1 Then
    Exit Sub
    End If
    If ActiveDocument.FullName <> "" Then
    Documents.Add Template:=ActiveDocument.FullName
    End If
    End Sub

    As you can tell, the macro also tests to make sure that there is at least
    one open document.

    --
    Stefan Blom
    Microsoft Word MVP




    "Ricky Marek" <> wrote in message
    news:...
    > 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.
    >
     
    Stefan Blom, Oct 19, 2013
    #2
    1. Advertisements

  3. Ricky Marek

    Stefan Blom Guest

    To ensure that the attached template is correct, try this code instead:

    Sub CreateNewDocBasedOnCurrentDoc()
    Dim TemplateName As String
    Dim NewDoc As Document
    If Documents.Count < 1 Then
    Exit Sub
    End If
    If ActiveDocument.FullName <> "" Then
    TemplateName = ActiveDocument.AttachedTemplate.FullName
    Set NewDoc = Documents.Add(Template:=ActiveDocument.FullName)
    NewDoc.AttachedTemplate = TemplateName
    End If
    End Sub

    --
    Stefan Blom
    Microsoft Word MVP




    "Stefan Blom" <> wrote in message
    news:l3tvfe$78o$...
    > You can use Documents.Add with the name of the current document as the
    > "template name." The requirement is that the current document has been
    > saved to disk. For example:
    >
    > Sub CreateNewDocBasedOnCurrentDoc()
    > If Documents.Count < 1 Then
    > Exit Sub
    > End If
    > If ActiveDocument.FullName <> "" Then
    > Documents.Add Template:=ActiveDocument.FullName
    > End If
    > End Sub
    >
    > As you can tell, the macro also tests to make sure that there is at least
    > one open document.
    >
    > --
    > Stefan Blom
    > Microsoft Word MVP
    >
    >
    >
    >
    > "Ricky Marek" <> wrote in message
    > news:...
    >> 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.
    >>
     
    Stefan Blom, Oct 19, 2013
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CAD Fiend
    Replies:
    5
    Views:
    248
    Jonathan West
    Jul 23, 2005
  2. Replies:
    4
    Views:
    521
    Jonathan West
    Jun 27, 2006
  3. Replies:
    3
    Views:
    95
    Kelie
    Mar 10, 2007
  4. robertf2
    Replies:
    1
    Views:
    97
    Jezebel
    Mar 20, 2007
  5. Replies:
    5
    Views:
    391
  6. Alan
    Replies:
    2
    Views:
    68
  7. randallc
    Replies:
    0
    Views:
    88
    randallc
    Apr 18, 2010
  8. Magnus Olsson
    Replies:
    2
    Views:
    169
    Magnus Olsson
    Sep 2, 2010
Loading...