Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Duplicate document on memory... is it possible (VBA, Word 2010 Macro)

Duplicate document on memory... is it possible (VBA, Word 2010 Macro)

Scheduled Pinned Locked Moved Visual Basic
comtoolsperformancequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rbid
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • R rbid

      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

      T Offline
      T Offline
      TnTinMn
      wrote on last edited by
      #2

      Perhaps 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups