Copy and paste

L

LEU

I was going through all the questions posted on coping and found almost what
I was looking for under a response by Doug Robbins. What I have is as follows:

Private Sub Copy1_Click()
With ActiveDocument
..Variables("varA").Value = Cmb1.Value
..Variables("varB").Value = Text1.Text
etc
..SaveAs ("c:\TempA")
End With
End Sub

Private Sub Paste1_Click()
Dim DocA As Document
Set DocA = Documents.Open("c:\TempA")
With DocA
Text1.Text = .Variables("varA").Value
Cmb1.Text = .Variables("varB").Value
etc
DocA.Close wdDoNotSaveChanges
End With
End Sub

My questions are in my Copy1_Click() how do I close "c:\TempA" after its
saved and in my Paste1_Click() how do I delete TempA when I’m done?
 
J

Jezebel

LEU said:
I was going through all the questions posted on coping and found almost
what
I was looking for under a response by Doug Robbins. What I have is as
follows:

Private Sub Copy1_Click()
With ActiveDocument
.Variables("varA").Value = Cmb1.Value
.Variables("varB").Value = Text1.Text
etc
.SaveAs ("c:\TempA")
End With
End Sub

Private Sub Paste1_Click()
Dim DocA As Document
Set DocA = Documents.Open("c:\TempA")
With DocA
Text1.Text = .Variables("varA").Value
Cmb1.Text = .Variables("varB").Value
etc
DocA.Close wdDoNotSaveChanges
End With
End Sub

My questions are in my Copy1_Click() how do I close "c:\TempA" after its
saved and in my Paste1_Click() how do I delete TempA when I'm done?

1.
.Close

2.
Kill "c:\TempA.doc"
 
L

LEU

The Kill "c:\TempA.doc" worked great.

On the .close it closes both my active document and "c:\TempA.doc". Is there
a way to just close "c:\TempA.doc"?

Thank you for the help.
LEU
 
J

Jezebel

On the .close it closes both my active document and "c:\TempA.doc". Is
there
a way to just close "c:\TempA.doc"?

You use the close method on the object that represents it. ActiveDocument in
the sample you post.

With ActiveDocument
:
.Close
End with

or simply ActiveDocument.Close
 
L

LEU

When I do the following both the ActiveDocumnet and ("c:\TempA") close. I
would like to keep the ActiveDocument open and just close ("c:\TempA"). Is
that possible?

Private Sub Copy1_Click()
With ActiveDocument
..Variables("varA").Value = Cmb1.Value
..Variables("varB").Value = Text1.Text
etc
..SaveAs ("c:\TempA")
..close
End With
End Sub
 
L

LEU

I’m stuck. I have looked at the help on document objects and their methods. I
thought I had it figured out, but I don’t. Here are the steps I am following:

1 I open my existing document.
2 I click on my CommandButton to open form
3 I click on my Copy button which I want to copy the fields in the form
using the following macro:

Private Sub Copy1_Click()
With ActiveDocument
..Variables("varA").Value = Cmd1.Value
..Variables("varB").Value = Text1.Text
etc
..SaveAs ("c:\TempA")
Documents("c:\TempA.doc").Close SaveChanges:=wdSaveChanges
End With
End Sub

This saves and closes TempA.Doc. It looks like using the ‘SaveAs’ is taking
my original document and making it TempA so when TempA closes there is no
original document still open. How do I keep my original existing document
open?
 
L

LEU

After talking to the group that request this I found out that the original
really does not need to stay open. So my code works fine as is.

Jezebel, I want to thank you for you help. I am glad that people like you
are out there and willing to help.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top