M
Malik Al-Amin
I'm trying to merge the contents of two documents. The two documents are
formatted as following:
Here's my situation. I have two documents. The first is formatted as
follows:
1. PreConditions
1.1. UCR332.1 Client Relationship is known.
1.2. UCR332.32 SA or PA has completed logon and initiated
UCR47 - AccessOnline Reporting.
1.3. UCR332.2 SA or PA has entitlement to run this report.
1.4. UCR332.33 SA or PA has selected the Transaction Approval
Status Report.
2. PostConditions
2.1. SA or PA has successfully run this report.
3. Flow of Events
3.1. Basic Flow
The second one is formatted as follows:
UCR332.1: Client Relationship is known.
UCR332.32: SA or PA has completed logon and initiated UCR47 - AccessOnline
Reporting.
UCR332.2: SA or PA has entitlement to run this report.
BR6534: The user must have the 'Client Administration Reports' entitlement
enabled.
UCR332.33: SA or PA has selected the Transaction Approval Status Report.
BR2883: The report will be part of the report group - Program Management
BR2889: The report will be part of the report subgroup - Administration
BR5267: Display the report list description as 'Transaction Approval Status
for Cardholder Accounts'.
My third document need to loop through document one and take a value such as
"UCR332.33 SA or PA has selected the Transaction Approval Status Report". It
needs to write that to a third document. Also I need to look for that value
in document 2. If the value in document 2 has any sub values (BR2883,
BR2889, BR5267) They need to be copied to the third document as well. The
result will look like:
UCR332.33 SA or PA has selected the Transaction Approval Status Report.
BR2883: The report will be part of the report group - Program Management
BR2889: The report will be part of the report subgroup - Administration
BR5267: Display the report list description as 'Transaction Approval
Status for Cardholder Accounts'.
This process needs to continue until the entire document one has been looped
through. What is the best way to loop through document 2? I'm use to the do
until end of file construct from vb. I don't quite know how to handle this
with word vba. I've worked out most of the logic but I'm unable to get my
code to move to the next paragraph in the range so I can evaluate it's
contents. Here's the code I have so far.
Sub Combine()
Dim TraceTree As Document 'variable referring to the TraceTree.doc
Dim UseCase As Document 'variable referring to UseCase.doc
Dim CaseTraceMerge As Document 'variable referring to the document that
will be created
'from the merge
Dim sCasePara As Paragraph 'variable referring to the current
paragraph in the usecase.doc
Dim sTracePara As Paragraph 'variable referring to the current
paragraph in the tracetree.doc
Dim pTraceToCopy As String 'variable referring to the tracetree
string to copy
Dim sMyPara As String 'variable referring to the usecase
string to copy
Dim MyRange As Range 'variable referring to the UseCase
document range
Dim TraceRange As Range 'Variable referring to the TraceTree
Document range
Dim strMyTrace As String
Dim colPosition As Integer 'variable used in the instr function to
keep track of colon
'starting point
Dim iParaCount As Integer 'variable for determining the total
paragraphs
Dim j As Integer 'variable keep a counter on the current
paragraph
' open the titles document in the background
Set TraceTree = Application.Documents.Open(FileName:="C:\Documents and
Settings\Malik\Desktop\TraceTree.doc", Visible:=False)
' open the info doc in the background
Set UseCase = Application.Documents.Open(FileName:="C:\Documents and
Settings\Malik\Desktop\usecase2.doc", Visible:=False)
Documents.Add.SaveAs FileName:="C:\Documents and
Settings\Malik\Desktop\CaseTraceMerge.doc"
Set CaseTraceMerge = Documents("CaseTraceMerge.doc")
iParaCount = UseCase.Paragraphs.Count
For j = 1 To iParaCount
sMyPara = UseCase.Paragraphs(j).Range.Text
For Each sCasePara In UseCase.Paragraphs
sMyPara = sCasePara.Range.Text
Set MyRange = CaseTraceMerge.Range
With MyRange
.ParagraphFormat.Alignment =
UseCase.Paragraphs(j).Alignment
.Collapse direction:=wdCollapseEnd
.InsertParagraphAfter
.Text = sMyPara
End With
For Each sTracePara In TraceTree.Paragraphs
colPosition = InStr(1, sTracePara.Range.Text, ":")
'pTraceToCopy = sTracePara.Range.Text
'Need to include error handling here incase we don't
have a colon
'In the trace tree
strMyTrace = Right(sTracePara.Range.Text,
Len(sTracePara.Range.Text) - colPosition)
strMyTrace = Trim(strMyTrace)
sMyPara = Trim(sMyPara)
If strMyTrace = sMyPara Then
sTracePara.Range.Move unit:=wdParagraph, Count:=1
pTraceToCopy = sTracePara.Range.Text
Set TraceRange = CaseTraceMerge.Range
'Set myRange = CaseTraceMerge.Range
If Not pTraceToCopy Like "UCR*" Then
If pTraceToCopy Like "BR*" Or pTraceToCopy Like
"INT*" Then
pTraceToCopy = sTracePara.Range.Text
With TraceRange
'.ParagraphFormat.LeftIndent =
InchesToPoints(1)
.ParagraphFormat.Alignment =
wdAlignParagraphLeft
.Collapse direction:=wdCollapseEnd
.InsertParagraphAfter
.Text = pTraceToCopy
.Bold = True
.Font.Name = "Arial"
.Italic = True
.Underline = True
.Font.Color = wdColorBlue
End With
End If
End If
End If
Next sTracePara
Next sCasePara
Next
MsgBox ("It's over Now")
CaseTraceMerge.Close wdSaveChanges
Set CaseTraceMerge = Nothing
TraceTree.Close wdDoNotSaveChanges
Set TraceTree = Nothing
End Sub
formatted as following:
Here's my situation. I have two documents. The first is formatted as
follows:
1. PreConditions
1.1. UCR332.1 Client Relationship is known.
1.2. UCR332.32 SA or PA has completed logon and initiated
UCR47 - AccessOnline Reporting.
1.3. UCR332.2 SA or PA has entitlement to run this report.
1.4. UCR332.33 SA or PA has selected the Transaction Approval
Status Report.
2. PostConditions
2.1. SA or PA has successfully run this report.
3. Flow of Events
3.1. Basic Flow
The second one is formatted as follows:
UCR332.1: Client Relationship is known.
UCR332.32: SA or PA has completed logon and initiated UCR47 - AccessOnline
Reporting.
UCR332.2: SA or PA has entitlement to run this report.
BR6534: The user must have the 'Client Administration Reports' entitlement
enabled.
UCR332.33: SA or PA has selected the Transaction Approval Status Report.
BR2883: The report will be part of the report group - Program Management
BR2889: The report will be part of the report subgroup - Administration
BR5267: Display the report list description as 'Transaction Approval Status
for Cardholder Accounts'.
My third document need to loop through document one and take a value such as
"UCR332.33 SA or PA has selected the Transaction Approval Status Report". It
needs to write that to a third document. Also I need to look for that value
in document 2. If the value in document 2 has any sub values (BR2883,
BR2889, BR5267) They need to be copied to the third document as well. The
result will look like:
UCR332.33 SA or PA has selected the Transaction Approval Status Report.
BR2883: The report will be part of the report group - Program Management
BR2889: The report will be part of the report subgroup - Administration
BR5267: Display the report list description as 'Transaction Approval
Status for Cardholder Accounts'.
This process needs to continue until the entire document one has been looped
through. What is the best way to loop through document 2? I'm use to the do
until end of file construct from vb. I don't quite know how to handle this
with word vba. I've worked out most of the logic but I'm unable to get my
code to move to the next paragraph in the range so I can evaluate it's
contents. Here's the code I have so far.
Sub Combine()
Dim TraceTree As Document 'variable referring to the TraceTree.doc
Dim UseCase As Document 'variable referring to UseCase.doc
Dim CaseTraceMerge As Document 'variable referring to the document that
will be created
'from the merge
Dim sCasePara As Paragraph 'variable referring to the current
paragraph in the usecase.doc
Dim sTracePara As Paragraph 'variable referring to the current
paragraph in the tracetree.doc
Dim pTraceToCopy As String 'variable referring to the tracetree
string to copy
Dim sMyPara As String 'variable referring to the usecase
string to copy
Dim MyRange As Range 'variable referring to the UseCase
document range
Dim TraceRange As Range 'Variable referring to the TraceTree
Document range
Dim strMyTrace As String
Dim colPosition As Integer 'variable used in the instr function to
keep track of colon
'starting point
Dim iParaCount As Integer 'variable for determining the total
paragraphs
Dim j As Integer 'variable keep a counter on the current
paragraph
' open the titles document in the background
Set TraceTree = Application.Documents.Open(FileName:="C:\Documents and
Settings\Malik\Desktop\TraceTree.doc", Visible:=False)
' open the info doc in the background
Set UseCase = Application.Documents.Open(FileName:="C:\Documents and
Settings\Malik\Desktop\usecase2.doc", Visible:=False)
Documents.Add.SaveAs FileName:="C:\Documents and
Settings\Malik\Desktop\CaseTraceMerge.doc"
Set CaseTraceMerge = Documents("CaseTraceMerge.doc")
iParaCount = UseCase.Paragraphs.Count
For j = 1 To iParaCount
sMyPara = UseCase.Paragraphs(j).Range.Text
For Each sCasePara In UseCase.Paragraphs
sMyPara = sCasePara.Range.Text
Set MyRange = CaseTraceMerge.Range
With MyRange
.ParagraphFormat.Alignment =
UseCase.Paragraphs(j).Alignment
.Collapse direction:=wdCollapseEnd
.InsertParagraphAfter
.Text = sMyPara
End With
For Each sTracePara In TraceTree.Paragraphs
colPosition = InStr(1, sTracePara.Range.Text, ":")
'pTraceToCopy = sTracePara.Range.Text
'Need to include error handling here incase we don't
have a colon
'In the trace tree
strMyTrace = Right(sTracePara.Range.Text,
Len(sTracePara.Range.Text) - colPosition)
strMyTrace = Trim(strMyTrace)
sMyPara = Trim(sMyPara)
If strMyTrace = sMyPara Then
sTracePara.Range.Move unit:=wdParagraph, Count:=1
pTraceToCopy = sTracePara.Range.Text
Set TraceRange = CaseTraceMerge.Range
'Set myRange = CaseTraceMerge.Range
If Not pTraceToCopy Like "UCR*" Then
If pTraceToCopy Like "BR*" Or pTraceToCopy Like
"INT*" Then
pTraceToCopy = sTracePara.Range.Text
With TraceRange
'.ParagraphFormat.LeftIndent =
InchesToPoints(1)
.ParagraphFormat.Alignment =
wdAlignParagraphLeft
.Collapse direction:=wdCollapseEnd
.InsertParagraphAfter
.Text = pTraceToCopy
.Bold = True
.Font.Name = "Arial"
.Italic = True
.Underline = True
.Font.Color = wdColorBlue
End With
End If
End If
End If
Next sTracePara
Next sCasePara
Next
MsgBox ("It's over Now")
CaseTraceMerge.Close wdSaveChanges
Set CaseTraceMerge = Nothing
TraceTree.Close wdDoNotSaveChanges
Set TraceTree = Nothing
End Sub