richardray
09-14-2012, 03:56 AM
Hi,
First post so hopefully I will have given you enough information to assist me with this issue!
I have a source Word document which has a VBA form to gather data that is inserted into DocVariables within the doc. The document is split into sections and depending on what tick boxes are selected on the form, different sections should be pasted into a new document.
The code for the document creation is as follows - the CLIENT document part is fine as that only contains one section:
Sub CreateInstallDocs()
'This is the part of the document that creates the separate Server and Client Install Docs as DOCX and PDF files
FilePath = ActiveDocument.Path & "\"
If ChkBxStandalone.Value = True Then
ActiveDocument.Sections(1).Range.Copy
Documents.Add
ActiveDocument.SaveAs2 (FilePath & TBCompanyName.Value & " Infor10 Server Install.docx")
Documents.Open (FilePath & TBCompanyName.Value & " Infor10 Server Install.docx")
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
Documents("Infor 10 Install-MultiDeployment.docm").Activate
ActiveDocument.Sections(2).Range.Copy
Documents(FilePath & TBCompanyName.Value & " Infor10 Server Install.docx").Activate
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
Documents("Infor 10 Install-MultiDeployment.docm").Activate
ActiveDocument.Sections(4).Range.Copy
Documents(FilePath & TBCompanyName.Value & " Infor10 Server Install.docx").Activate
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
ActiveDocument.Save
ActiveDocument.Close
' CLIENT DOCUMENT
ActiveDocument.Sections(5).Range.Copy
Documents.Add
ActiveDocument.SaveAs2 (FilePath & TBCompanyName.Value & " Infor10 Client Install.docx")
Documents.Open (FilePath & TBCompanyName.Value & " Infor10 Client Install.docx")
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
ActiveDocument.Save
ActiveDocument.Close
End If
At the moment, only the last section is pasted which overwrites all other sections that should be in that document. I obviously need an append method but my VBA isn't too hot and I have inherited this from someone else.
Many thanks in advance,
Richard
First post so hopefully I will have given you enough information to assist me with this issue!
I have a source Word document which has a VBA form to gather data that is inserted into DocVariables within the doc. The document is split into sections and depending on what tick boxes are selected on the form, different sections should be pasted into a new document.
The code for the document creation is as follows - the CLIENT document part is fine as that only contains one section:
Sub CreateInstallDocs()
'This is the part of the document that creates the separate Server and Client Install Docs as DOCX and PDF files
FilePath = ActiveDocument.Path & "\"
If ChkBxStandalone.Value = True Then
ActiveDocument.Sections(1).Range.Copy
Documents.Add
ActiveDocument.SaveAs2 (FilePath & TBCompanyName.Value & " Infor10 Server Install.docx")
Documents.Open (FilePath & TBCompanyName.Value & " Infor10 Server Install.docx")
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
Documents("Infor 10 Install-MultiDeployment.docm").Activate
ActiveDocument.Sections(2).Range.Copy
Documents(FilePath & TBCompanyName.Value & " Infor10 Server Install.docx").Activate
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
Documents("Infor 10 Install-MultiDeployment.docm").Activate
ActiveDocument.Sections(4).Range.Copy
Documents(FilePath & TBCompanyName.Value & " Infor10 Server Install.docx").Activate
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
ActiveDocument.Save
ActiveDocument.Close
' CLIENT DOCUMENT
ActiveDocument.Sections(5).Range.Copy
Documents.Add
ActiveDocument.SaveAs2 (FilePath & TBCompanyName.Value & " Infor10 Client Install.docx")
Documents.Open (FilePath & TBCompanyName.Value & " Infor10 Client Install.docx")
ActiveDocument.Range.PasteAndFormat (wdUseDestinationStylesRecovery)
ActiveDocument.Save
ActiveDocument.Close
End If
At the moment, only the last section is pasted which overwrites all other sections that should be in that document. I obviously need an append method but my VBA isn't too hot and I have inherited this from someone else.
Many thanks in advance,
Richard