I populate a word doc from an excel spreadsheet using doc variables.
This document will enventually go to a client, so I would like the
DocVariables "removed", while keeping the values themselves. similar
to a copy / pastespecial / values works in excel.

I can accomplish this manually in word by highlighting the variable,
hitting copy / paste special / unformatted text. However, when I try
to do so in VBA, it seems to simply copy back the DocVariable.

Here is the code:

set wrdApp = Word.Application
Dim myField As Field
For Each myField In ActiveDocument.Fields
Debug.Print myField.Code
myField.Result.Select
wrdApp.Selection.Copy
wrdApp.Selection.PasteAndFormat (wdFormatPlainText)
Next

Why would this work manually, but not via VBA? I've tried other
(wdFormat...) options, but with the same result.

Thanks for any help!!!

Re: DocVariables - Copy / PasteSpecial by Jean-Guy

Jean-Guy
Fri Jul 07 11:44:08 CDT 2006

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

> I populate a word doc from an excel spreadsheet using doc variables.
> This document will enventually go to a client, so I would like the
> DocVariables "removed", while keeping the values themselves. similar
> to a copy / pastespecial / values works in excel.
>
> I can accomplish this manually in word by highlighting the variable,
> hitting copy / paste special / unformatted text. However, when I try
> to do so in VBA, it seems to simply copy back the DocVariable.

You are using a jackhammer to punch a hole through paper! ;-)

It is much easier to simply unlink the field:

To unlink only document variable fields:

'_______________________________________
Sub UnlinkDocVar()

Dim myField As Field

For Each myField In ActiveDocument.Fields
If myField.Type = wdFieldDocVariable Then myField.Unlink
Next

End Sub
'_______________________________________

To unlink all fields:
'_______________________________________
Sub UnlinkAllVar()

ActiveDocument.Fields.Unlink

End Sub
'_______________________________________

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



Re: DocVariables - Copy / PasteSpecial by erikrthorne

erikrthorne
Fri Jul 07 13:54:23 CDT 2006

Holy Cow...you made my whole weekend. I'm a little better on the Excel
side than I am the Word side, you have no idea how long I was trying to
get that jackhammer to work! My first post to the group, and a
solution in under an hour....Awesome, and Thank you!

Erik Thorne

Jean-Guy Marcil wrote:
> erikrthorne@gmail.com was telling us:
> erikrthorne@gmail.com nous racontait que :
>
> > I populate a word doc from an excel spreadsheet using doc variables.
> > This document will enventually go to a client, so I would like the
> > DocVariables "removed", while keeping the values themselves. similar
> > to a copy / pastespecial / values works in excel.
> >
> > I can accomplish this manually in word by highlighting the variable,
> > hitting copy / paste special / unformatted text. However, when I try
> > to do so in VBA, it seems to simply copy back the DocVariable.
>
> You are using a jackhammer to punch a hole through paper! ;-)
>
> It is much easier to simply unlink the field:
>
> To unlink only document variable fields:
>
> '_______________________________________
> Sub UnlinkDocVar()
>
> Dim myField As Field
>
> For Each myField In ActiveDocument.Fields
> If myField.Type = wdFieldDocVariable Then myField.Unlink
> Next
>
> End Sub
> '_______________________________________
>
> To unlink all fields:
> '_______________________________________
> Sub UnlinkAllVar()
>
> ActiveDocument.Fields.Unlink
>
> End Sub
> '_______________________________________
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org