What's the easiest way to copy all form fields of a Word document to the clipboard? Form is a simple protected Word form with only text fields. 14 of them. No formatting needed. Paste from clipboard OK to have field data run on, from one to the next.
Is there a procedure if Word that does this? Should I use a macro? Is there another way?
Thanks,
Dax
Copy Form Fields to Clipboard
-
- 3StarLounger
- Posts: 368
- Joined: 04 Jan 2012, 22:43
Copy Form Fields to Clipboard
It takes 2 to tango; unless you speak binary; then it takes 10.
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Copy Form Fields to Clipboard
I think you'll need a macro for this, so activate the Visual Basic Editor.
If your document does not contain a userform, create one (Insert > Userform), then immediately remove it again. This seems silly, but it creates a reference to the Forms library that we'll need.
If your document already contained a userform, you can skip the previous step.
Copy the following macro into an existing or new code module:
Running this macro will copy the contents of the form fields in the document to the clipboard as a long string, concatenated with commas. You can paste it anywhere you need it.
If your document does not contain a userform, create one (Insert > Userform), then immediately remove it again. This seems silly, but it creates a reference to the Forms library that we'll need.
If your document already contained a userform, you can skip the previous step.
Copy the following macro into an existing or new code module:
Code: Select all
Sub CopyFields()
Dim fld As FormField
Dim objData As New MSForms.DataObject
Dim strText As String
For Each fld In ActiveDocument.FormFields
strText = strText & ", " & fld.Result
Next fld
strText = Mid(strText, 3)
With objData
.SetText Text:=strText
.PutInClipboard
End With
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 368
- Joined: 04 Jan 2012, 22:43
Re: Copy Form Fields to Clipboard
SWEETNESS! Again! You're the man!
Thank you, thank you, thank you!
Thank you, thank you, thank you!
It takes 2 to tango; unless you speak binary; then it takes 10.