Complex Macro for Doc to Template, and Vice Versa

D

dschenkler

Hello
A Requirements Program I have has a tool that allows me to generate documents containing information from Program into a MS Word document by using a MS Template that I created. The information in the tool is divided into Parents & Children, and other sections and stuff.
The template is divided into the different categories of requirements in the Program, but after running the tool and using my other Macros, the document generated comes out nice, with the Children going into their sections and everything going under the utmost Parent. I have tables and other stuff in my template.
The template works great for one (main) Parent, but not for two (main) Parents. If I generate the report, all the information from the Parent1 goes into Parent2, and all of the information from both Parents intermingles.
Example: I have SCRN1 and SCRN2. SCRN1 and SCRN2 contain Commands, Fields, Wireframes, and etcetera. After running, all of the Commands and Fields, and etcetera of SCRN1 will go under SCRN2 and will also be combined into the same tables and locations as the Commands and Fields, and etcetera from SCRN2.

The following Macro I created, but it does not work.

Private Sub InsertID2AfterID1()


Const REQTREE = "$REQTREE{FirstRequirementTreeID,NextRequirementTreeID}"

Dim FirstRequirementTreeID As RequirementTreeID
Dim NextRequirementTreeID As RequirementTreeID
Dim p As Object
Dim n As Object
Set p = FirstRequirementTreeID
Set n = NextRequirementTreeID
Dim myRange As Range
Set myRange = ActiveDocument.GoTo.Application.Templates
myRange.Find.Execute MatchSoundsLike:="$REQTREE{p,n}"
If myRange.Find.found Then
If myRange.Text Like "p" Then
Selection.HomeKey Unit:=wdStory
End If

If myRange.Text Like "n" Then
' Select "n" and put all of its requirements at the end of the document by inserting BB
Dim q As Long
For q = 2 To NextRequirementTreeID
With ActiveDocument.Content
Dim requirementID As String
Dim reqId As Long
reqId = CLng(requirementID)
Dim objRequirement As Requirement
Set objRequirement = objSession.getRequirement(reqId)
While n = objRequirement.ParentRequirement
Dim objChildren As IStCollection
Set objChildren = objRequirement.ChildRequirements
Selection.Range.Select
Selection.Range.Cut
Dim myTemplate As Document
Set myTemplate = Documents.Add
Documents.Add Template:="U:\BDSDOC\Projects\SOSA Phase 1\Caliber\Files\ReportTemplates\Production\TestReports\Screen Report Templates\DF1_Screen_MacrosTemplate-Multiple Screens_Trial.3.dot"
.InsertAfter "end of document"
Selection.Range.PasteSpecial myTemplate
Wend
End With
Next q
End If
End If
End Sub



If someone can help me I would really appreciate it.

Thank you so much in advance!!!!!
 

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