I have figured out a way to copy paste a table (with fieldforms). I
have a macro button in my doc. which when I press copies the table in
the doc. and pastes it. The code to do the that is below:

Private Sub CommandButton1_Click()
Set aDoc = ActiveDocument
If aDoc.ProtectionType <> wdNoProtection Then
aDoc.Unprotect
ActiveDocument.Tables(2).Range.Copy
Set myRange = ActiveDocument.Range _
(Start:=ActiveDocument.Content.End - 1, _
End:=ActiveDocument.Content.End - 1)
myRange.PasteSpecial


aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

Now, when the user fills in data in the table cells and then presses
the macro button, the pasted table has the same data in its cells. Is
there a way I could make sure that only the table is copy-pasted and
not the data inside it?
Any help would be great! Thank You

Re: Copy Paste Table Problems! by Jean-Guy

Jean-Guy
Tue Nov 28 18:28:15 CST 2006

rachitm@gmail.com was telling us:
rachitm@gmail.com nous racontait que :

> I have figured out a way to copy paste a table (with fieldforms). I
> have a macro button in my doc. which when I press copies the table in
> the doc. and pastes it. The code to do the that is below:
>
> Private Sub CommandButton1_Click()
> Set aDoc = ActiveDocument
> If aDoc.ProtectionType <> wdNoProtection Then
> aDoc.Unprotect
> ActiveDocument.Tables(2).Range.Copy
> Set myRange = ActiveDocument.Range _
> (Start:=ActiveDocument.Content.End - 1, _
> End:=ActiveDocument.Content.End - 1)
> myRange.PasteSpecial
>
>
> aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> End If
> End Sub
>
> Now, when the user fills in data in the table cells and then presses
> the macro button, the pasted table has the same data in its cells. Is
> there a way I could make sure that only the table is copy-pasted and
> not the data inside it?
> Any help would be great! Thank You

How about this:

'_______________________________________
Dim aDoc As Document
Dim myRange As Range

Set aDoc = ActiveDocument
With aDoc
If .ProtectionType <> wdNoProtection Then
.Unprotect
.Tables(2).Range.Copy
Set myRange = .Range(Start:=.Content.End - 1, _
End:=.Content.End - 1)
myRange.PasteSpecial
.Tables(.Tables.Count).Range.Delete
aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Copy Paste Table Problems! by rachitm

rachitm
Wed Nov 29 08:41:15 CST 2006

Thanks Jean! This does work to some extent. But I have a table which
has formfields and some info inside other cells that I still need to be
copied into the new table....Bascically I just need formfields (empty)
to be copied...as some cell info.

eg.

heading 1 I <formfield> I
heading 2 I <formfield> I
heading 3 I <formfield> I
heading 4 I <formfield> I

I want all the headings to be copied and the formfields to be copied,
but the formfields should be empty.

Thanks




Jean-Guy Marcil wrote:
> rachitm@gmail.com was telling us:
> rachitm@gmail.com nous racontait que :
>
> > I have figured out a way to copy paste a table (with fieldforms). I
> > have a macro button in my doc. which when I press copies the table in
> > the doc. and pastes it. The code to do the that is below:
> >
> > Private Sub CommandButton1_Click()
> > Set aDoc = ActiveDocument
> > If aDoc.ProtectionType <> wdNoProtection Then
> > aDoc.Unprotect
> > ActiveDocument.Tables(2).Range.Copy
> > Set myRange = ActiveDocument.Range _
> > (Start:=ActiveDocument.Content.End - 1, _
> > End:=ActiveDocument.Content.End - 1)
> > myRange.PasteSpecial
> >
> >
> > aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> > End If
> > End Sub
> >
> > Now, when the user fills in data in the table cells and then presses
> > the macro button, the pasted table has the same data in its cells. Is
> > there a way I could make sure that only the table is copy-pasted and
> > not the data inside it?
> > Any help would be great! Thank You
>
> How about this:
>
> '_______________________________________
> Dim aDoc As Document
> Dim myRange As Range
>
> Set aDoc = ActiveDocument
> With aDoc
> If .ProtectionType <> wdNoProtection Then
> .Unprotect
> .Tables(2).Range.Copy
> Set myRange = .Range(Start:=.Content.End - 1, _
> End:=.Content.End - 1)
> myRange.PasteSpecial
> .Tables(.Tables.Count).Range.Delete
> aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> End If
> End With
> '_______________________________________
>
> --
>
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org


Re: Copy Paste Table Problems! by Jean-Guy

Jean-Guy
Wed Nov 29 10:16:14 CST 2006

rachitm@gmail.com was telling us:
rachitm@gmail.com nous racontait que :

> Thanks Jean! This does work to some extent. But I have a table which
> has formfields and some info inside other cells that I still need to
> be copied into the new table....Bascically I just need formfields
> (empty) to be copied...as some cell info.
>
> eg.
>
> heading 1 I <formfield> I
> heading 2 I <formfield> I
> heading 3 I <formfield> I
> heading 4 I <formfield> I
>
> I want all the headings to be copied and the formfields to be copied,
> but the formfields should be empty.

Try this then (This assumes that your formfields have a default value and
that the first item in a dropdown is not an actual choice, but something
like "Select please"...):

'_______________________________________
Dim aDoc As Document
Dim myRange As Range
Dim ffToReset As FormFields
Dim i As Long

Set aDoc = ActiveDocument
With aDoc
If .ProtectionType <> wdNoProtection Then
.Unprotect
.Tables(2).Range.Copy
Set myRange = .Range(Start:=.Content.End - 1, _
End:=.Content.End - 1)
myRange.PasteSpecial
Set myRange = .Tables(.Tables.Count).Range
aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
With myRange
Set ffToReset = .FormFields
If ffToReset.Count > 0 Then
For i = 1 To ffToReset.Count
Select Case ffToReset(i).Type
Case wdFieldFormTextInput
ffToReset(i).Result =
ffToReset(i).TextInput.Default
Case wdFieldFormCheckBox
ffToReset(i).CheckBox.Value = False
Case wdFieldFormDropDown
ffToReset(i).DropDown.Value = 1
End Select
Next
End If
End With
End If
End With
'_______________________________________

Please, try to be more explicit next time...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Copy Paste Table Problems! by rachitm

rachitm
Wed Nov 29 10:33:21 CST 2006

This is awesome Jean! this is perfect! thank you so much for your help
:)



Jean-Guy Marcil wrote:
> rachitm@gmail.com was telling us:
> rachitm@gmail.com nous racontait que :
>
> > Thanks Jean! This does work to some extent. But I have a table which
> > has formfields and some info inside other cells that I still need to
> > be copied into the new table....Bascically I just need formfields
> > (empty) to be copied...as some cell info.
> >
> > eg.
> >
> > heading 1 I <formfield> I
> > heading 2 I <formfield> I
> > heading 3 I <formfield> I
> > heading 4 I <formfield> I
> >
> > I want all the headings to be copied and the formfields to be copied,
> > but the formfields should be empty.
>
> Try this then (This assumes that your formfields have a default value and
> that the first item in a dropdown is not an actual choice, but something
> like "Select please"...):
>
> '_______________________________________
> Dim aDoc As Document
> Dim myRange As Range
> Dim ffToReset As FormFields
> Dim i As Long
>
> Set aDoc = ActiveDocument
> With aDoc
> If .ProtectionType <> wdNoProtection Then
> .Unprotect
> .Tables(2).Range.Copy
> Set myRange = .Range(Start:=.Content.End - 1, _
> End:=.Content.End - 1)
> myRange.PasteSpecial
> Set myRange = .Tables(.Tables.Count).Range
> aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> With myRange
> Set ffToReset = .FormFields
> If ffToReset.Count > 0 Then
> For i = 1 To ffToReset.Count
> Select Case ffToReset(i).Type
> Case wdFieldFormTextInput
> ffToReset(i).Result =
> ffToReset(i).TextInput.Default
> Case wdFieldFormCheckBox
> ffToReset(i).CheckBox.Value = False
> Case wdFieldFormDropDown
> ffToReset(i).DropDown.Value = 1
> End Select
> Next
> End If
> End With
> End If
> End With
> '_______________________________________
>
> Please, try to be more explicit next time...
>
> --
>
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org


Re: Copy Paste Table Problems! by rachitm

rachitm
Thu Nov 30 13:57:37 CST 2006

I didnt realize till today, but when you press the button to copy paste
the table the 2nd time, it erases the info off the table that was
created when the button was pressed the 1st time. What could be done
about that?

Also, is there a way to create space between all the pasted tables?
That could be one way of solving this problem.

Thanks


rachitm@gmail.com wrote:
> This is awesome Jean! this is perfect! thank you so much for your help
> :)
>
>
>
> Jean-Guy Marcil wrote:
> > rachitm@gmail.com was telling us:
> > rachitm@gmail.com nous racontait que :
> >
> > > Thanks Jean! This does work to some extent. But I have a table which
> > > has formfields and some info inside other cells that I still need to
> > > be copied into the new table....Bascically I just need formfields
> > > (empty) to be copied...as some cell info.
> > >
> > > eg.
> > >
> > > heading 1 I <formfield> I
> > > heading 2 I <formfield> I
> > > heading 3 I <formfield> I
> > > heading 4 I <formfield> I
> > >
> > > I want all the headings to be copied and the formfields to be copied,
> > > but the formfields should be empty.
> >
> > Try this then (This assumes that your formfields have a default value and
> > that the first item in a dropdown is not an actual choice, but something
> > like "Select please"...):
> >
> > '_______________________________________
> > Dim aDoc As Document
> > Dim myRange As Range
> > Dim ffToReset As FormFields
> > Dim i As Long
> >
> > Set aDoc = ActiveDocument
> > With aDoc
> > If .ProtectionType <> wdNoProtection Then
> > .Unprotect
> > .Tables(2).Range.Copy
> > Set myRange = .Range(Start:=.Content.End - 1, _
> > End:=.Content.End - 1)
> > myRange.PasteSpecial
> > Set myRange = .Tables(.Tables.Count).Range
> > aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> > With myRange
> > Set ffToReset = .FormFields
> > If ffToReset.Count > 0 Then
> > For i = 1 To ffToReset.Count
> > Select Case ffToReset(i).Type
> > Case wdFieldFormTextInput
> > ffToReset(i).Result =
> > ffToReset(i).TextInput.Default
> > Case wdFieldFormCheckBox
> > ffToReset(i).CheckBox.Value = False
> > Case wdFieldFormDropDown
> > ffToReset(i).DropDown.Value = 1
> > End Select
> > Next
> > End If
> > End With
> > End If
> > End With
> > '_______________________________________
> >
> > Please, try to be more explicit next time...
> >
> > --
> >
> > Salut!
> > _______________________________________
> > Jean-Guy Marcil - Word MVP
> > jmarcilREMOVE@CAPSsympatico.caTHISTOO
> > Word MVP site: http://www.word.mvps.org


Re: Copy Paste Table Problems! by Jean-Guy

Jean-Guy
Thu Nov 30 14:41:33 CST 2006

rachitm@gmail.com was telling us:
rachitm@gmail.com nous racontait que :

> I didnt realize till today, but when you press the button to copy
> paste the table the 2nd time, it erases the info off the table that
> was created when the button was pressed the 1st time. What could be
> done about that?
>
> Also, is there a way to create space between all the pasted tables?
> That could be one way of solving this problem.

The problem you observed is caused by the fact that the second time you use
the function, the second new table is joined to the first new table, thus
making one bigger table.

Once again, I must reiterate, please, next time you post a question, explain
the extent of what you are trying to achieve and how a typical user will
interact with your document... You never mentioned that the function would
be used more than once, so, when I tested my code. I never tested for
that...I just assumed that it would be used once.

Try this:

'_______________________________________
Dim aDoc As Document
Dim myRange As Range
Dim ffToReset As FormFields
Dim i As Long

Set aDoc = ActiveDocument
With aDoc
If .ProtectionType <> wdNoProtection Then
.Unprotect
.Tables(2).Range.Copy
Set myRange = .Range(Start:=.Content.End - 1, _
End:=.Content.End - 1)
With myRange
.InsertParagraphAfter
.Collapse wdCollapseStart
.PasteSpecial
End With
Set myRange = .Tables(.Tables.Count).Range
aDoc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
With myRange
Set ffToReset = .FormFields
If ffToReset.Count > 0 Then
For i = 1 To ffToReset.Count
Select Case ffToReset(i).Type
Case wdFieldFormTextInput
ffToReset(i).Result =
ffToReset(i).TextInput.Default
Case wdFieldFormCheckBox
ffToReset(i).CheckBox.Value = False
Case wdFieldFormDropDown
ffToReset(i).DropDown.Value = 1
End Select
Next
End If
End With
End If
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org