Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy all form fields from one word document to other

Status
Not open for further replies.

barnard90

IS-IT--Management
Mar 6, 2005
73
US
Hi

I have an active Word document (Employee Info.doc) , which I am currently working on . This is the active document

I need to write a macro which would dynamically open another new word document and copy all the values of the Form fields of Employee Info.doc into the new document

How do I do it in Word macros
Could someone please suggest the code

thanks

 
You may consider the ActiveDocument.FormFields collection.
What have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
For my current Active document , I can use the ActiveDocument.FormFields collection

But how do I copy onto the new document which has to be dynamically created ?
I am not sure how I can use ActiveDocument.FormFields collection for a dynamically created document
 
Let's be careful here. Does it matter where the text goes??? If you just want to get the text formfield results, and dump them into a new document, then:
Code:
Sub CopyAllFF()
[COLOR=red]' make formfield object variable[/color red]
Dim oFF As Word.FormField

[COLOR=red]' make document variables[/color red]
Dim ThisDoc As Document
Dim ThatDoc As Document

[COLOR=red]' make string array for formfield results[/color red]
Dim formfieldResults()

[COLOR=red]' various variables[/color red]
Dim i As Integer
Dim var

[COLOR=red]' set doc variables, including NEW one[/color red]
Set ThisDoc = ActiveDocument
Documents.Add
Set ThatDoc = ActiveDocument
ThisDoc.Activate

[COLOR=red]' build string array of formfield results[/color red]
For Each oFF In ThisDoc.FormFields
   ReDim Preserve formfieldResults(i)
   formfieldResults(i) = oFF.Result
   i = i + 1
Next
[COLOR=red]' activate NEW doc
' insert other doc formfield strings
' separated by paragraph mark[/color red]
ThatDoc.Activate
For var = 0 To UBound(formfieldResults())
   Selection.TypeText Text:=formfieldResults(var) _
      & vbCrLf
Next

[COLOR=red]' clear doc objects[/color red]
Set ThatDoc = Nothing
Set ThisDoc = Nothing
End Sub
There are certainly other ways to do this. The most important thing is....WHAT do you want to do with the text of the formfields????

Gerry
My paintings and sculpture
 
Oh, and I should mention that I made the Sub CopyAllFF the OnExit macro for the last text formfield. So when you tab out of the last formfield, the procedure fires.

You may of course - and probably - may have another point that you want to fire the procedure. A hotkey. A macro icon on the toolbar. You may, or may not, want it to be done auotmatically.

Gerry
My paintings and sculpture
 
Fumie

Thanks for your post
That was pretty useful
 
Yeah, well, you still need to be careful and explicit about what you are going to do. Remember, that string array is built from the text formfield results. If the formfield result is blank, the array will still be built with an item, of "".

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top