General discussion

Locked

Word document copy

By hurdk ·
I have a Word document.
I have a command button on the Word document.
I want to click on the command button and copy one Word document with another Word document.
Example: DocumentA in directoryB replaces
DocumentA in directoryA.
Thank you.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Word document copy

by grybyx In reply to Word document copy

I see two scenarios in your question. First, you want to replace an existing file with the active document. Second, you want the active document to manage the replacement of one file with another.

Here's my solution to the first scenario:

Private Sub CommandButton1_Click()
Const DestFileName As String = "C:\My Documents\dest.doc"
Dim temp As String

temp = ActiveDocument.FullName
ActiveDocument.SaveAs FileName:=DestFileName
Documents.Open FileName:=temp
Documents(DestFileName).Close
End Sub

The above routine will save the active document in another location, keeping the active document active afterward.

Here's my solution to the second scenario:

Private Sub CommandButton1_Click()
Const SrcFileName As String = "C:\My Documents\src.doc"
Const DestFileName As String = "C:\My Documents\dest.doc"
Dim temp As String

temp = ActiveDocument.FullName
Documents.Open FileName:=SrcFileName
Documents(SrcFileName).SaveAs FileName:=DestFileName
Documents.Open FileName:=temp
Documents(DestFileName).Close
End Sub

The above routine will replace C:\My Documents\dest.doc with C:\My Documents\src.doc.

Happy Programming!

Collapse -

Word document copy

by hurdk In reply to Word document copy

This answer is a very professional response. The code has definitely helped me. Thank you.

Collapse -

Word document copy

by hurdk In reply to Word document copy

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums