Copy FormFields to Other Documents - Word 2007

C

Cole

Private Sub CommandButtonSave_Click()

Dim strDirPath, strNewSourceName, strNewFolder
Dim Source As Document
Dim oFF As FormField
Dim Test
strDirPath = "\\NT01234D\CCBDOCS:\BBX\"
Set Source = ActiveDocument
strNewSourceName = "MySourceDoc.docm"

Test = Source.FormFields.Count

'Find the new folder name:
For Each oFF In Source.FormFields
If oFF.Name = "ClearQuest_ID" Then
strNewFolder = Source.FormFields(oFF.Name).Result
End If
Next oFF

' Open folder - if does not exist, create it:
Dim myfolder As String
myfolder = "\\NT01234D\CCBDOCS:\BBX\" & strNewFolder
If Len(Dir(myfolder)) = 0 Then
Dim fso, fldr
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set fldr = fso.CreateFolder(myfolder)
End If

'Save the Document:
ActiveDocument.SaveAs (myfolder & "Mag-E.docm")

'Open Target1 Template doc and SaveAs to project folder:

Dim Target1 As Document
Set Target1 = Application.Windows(strDirPath & "Testing
Approvals.dotm").Document
Target1.SaveAs (myfolder & "Testing Approvals.docm")

'Copy the FormFields From Source (This Doc) to Target1:

Dim Source As Document
Dim Target As Document
Dim ff As FormField
Set Source = Application.Windows(myfolder & "Mag-E.docm").Document
Set Target = Application.Windows(myfolder & "Testing
Approvals.docm").Document
For Each ff In Target.FormFields
ff.Result = Source.FormFields(ff.Name).Result
Next ff

'Next do the same for Target2 & Target3:
'Etc.

End Sub
 

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