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
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