Consulting

Results 1 to 6 of 6

Thread: How to Make Copy of Word Document

  1. #1
    VBAX Regular
    Joined
    Aug 2006
    Posts
    36
    Location

    How to Make Copy of Word Document

    This should be easy, but I'm stumped. I have a "Master" copy of a .doc file that I don't want to jeopardize changing with VBA, and I don't want to use a template (.dot) because I'm not a big fan of the normal.dot conflicts.

    So, the flow of the Excel VBA code is to make a copy of the master word .doc, then to transfer data from Excel to that copy.

    Here's a copy of what I tried:

    Sub Project_Text()
        Dim objWord As Object
        
        Set objWord = CreateObject("Word.Application")
        objWord.Visible = True
        objWord.Documents.Copy "C:\Master Project Text.doc"
        objWord.Documents.Paste "C:\Master Project Text.doc"
    Last edited by Aussiebear; 09-29-2013 at 02:39 AM. Reason: Added tags to code

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    833
    Location
    HTH. Dave
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    'source,destination,save
    FSO.CopyFile "C:\Master Project Text.doc", _
        "C:\Master Project TextCopy.doc", True
    Set FSO = Nothing

  3. #3
    VBAX Regular
    Joined
    Aug 2006
    Posts
    36
    Location
    That's perfect...

    Thank you!

  4. #4
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    You can do this without FSO as well
    FileCopy "C:\Master Project Text.doc", "C:\Master Project TextCopy.doc"
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Option Explicit
    
    Private Sub Document_Open()
    'Only runs RenameMe from the Original.
    
    If Me.Name = "Master Project Text.doc" Then ReNameMe
    End Sub
    Private Sub ReNameMe()
    'Creates a copy of and closes the original.
    'To modify to the original modify this new copy and save it as "C:\Master Project Text.doc"
    ' or disable Macros when opening the original.
    
    Me.SaveAs ("C:\Master Project TextCopy.doc")
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Please read the helpfile of Word's VBEditor.

    Sub M_snb() 
      with CreateObject("Word.Application") 
        .visible=true
        with .documents.add("C:\Master Project Text.doc") 
           .saveas2 "C:\Master Project Text_002.docx" 
        end with
      end with
    end sub
    I don't want to use a template (.dot) because I'm not a big fan of the normal.dot conflicts
    That never occur. You are fighting a phantom...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •