R
Rod Makin
OK enough of the obvious jokes - "Yeah, ya 'aint got no style dude!"
Anyway I have some word documents which have a style structure so the
documents look consistent. It goes something like
Header1
Header2
Header3
Header4
Reference
Content
Header4
Reference
Content
Header4
Reference
Content
Header4
Reference
Content
Now the reason I am having problems is that I want to pick out these
heading4's, the references, and contents and export them into word. I have
some code that does this already (I'll post at bottom), but it does this by
counting the paragraph styles. Which works to a point but sometimes,
invisibly people will leave in the odd header 3, or header 2, this screws up
the counting. Is there a better way of doing this?
The code is below, not in its entirity but enough to show you what its
doing.
'Reserve resource for database object called loerecord
'open a blank LOE recorder
' Set dbase = CurrentDb
For Each aparagraph In ActiveDocument.Paragraphs
'Extract document number from document
If aparagraph.Style = "Body Text" Then
If projnumfound = False Then
crPos = InStr(aparagraph, " ")
'docnum = Trim(Left$(aparagraph, crPos - 1))
projnumfound = True
End If
End If
'1111111111111111111111111111111111111111111111111111111111111111111111111111111111
'check on level number and dont print it until in section two
If aparagraph.Style.ListLevelNumber = 1 Then
If testCaseUnderPrep = True Then
testnum = document_no & " - " & onecounter & "." & twocounter &
"." & threecounter & "." & fourcounter
insert_data document_no, project_no, testnum, parah1, parah2,
parah3, parah4, refpara, testcase, testCaseUnderPrep, overwrite_duplicates,
dbase
End If
onecounter = onecounter + 1
twocounter = 0
threecounter = 0
fourcounter = 0
parah1 = aparagraph & " "
End If
'22222222222222222222222222222222222222222222222222222222222222222222222222222222222
If aparagraph.Style.ListLevelNumber = 2 Then
If testCaseUnderPrep = True Then
testnum = document_no & " - " & onecounter & "." & twocounter &
"." & threecounter & "." & fourcounter
insert_data document_no, project_no, testnum, parah1, parah2,
parah3, parah4, refpara, testcase, testCaseUnderPrep, overwrite_duplicates,
dbase
End If
twocounter = twocounter + 1
threecounter = 0
fourcounter = 0
parah2 = aparagraph & " "
End If
'3333333333333333333333333333333333333333333333333333333333333333333333333333333333If aparagraph.Style.ListLevelNumber = 3 Then If testCaseUnderPrep = True Then testnum = document_no & " - " & onecounter & "." & twocounter&"." & threecounter & "." & fourcounter insert_data document_no, project_no, testnum, parah1,parah2,parah3, parah4, refpara, testcase, testCaseUnderPrep,overwrite_duplicates,dbase End If threecounter = threecounter + 1 fourcounter = 0 parah3 = aparagraph & " " End If'44444444444444444444444444444444444444444444444444444444444444444444444444444444444 If aparagraph.Style.ListLevelNumber = 4 Then threeEncountered = False If testCaseUnderPrep = True Then testnum = document_no & " - " & onecounter & "." & twocounter&"." & threecounter & "." & fourcounter insert_data document_no, project_no, testnum, parah1,parah2,parah3, parah4, refpara, testcase, testCaseUnderPrep,overwrite_duplicates,dbase End If fourcounter = fourcounter + 1 parah4 = aparagraph & " " End If If aparagraph.Style = "TC_Reference" Then refpara = aparagraph & " " End If If aparagraph.Style = "Testcase" Then testCaseUnderPrep = True tmp_testcase = aparagraph testcase = testcase & tmp_testcase End IfNext ' MsgBox ("finishing") dbase.Close Set dbase = Nothing loerecord.CloseCurrentDatabase loerecord.Quit Set loerecord = Nothing MsgBox ("Finshed!")End SubCheersRod
Anyway I have some word documents which have a style structure so the
documents look consistent. It goes something like
Header1
Header2
Header3
Header4
Reference
Content
Header4
Reference
Content
Header4
Reference
Content
Header4
Reference
Content
Now the reason I am having problems is that I want to pick out these
heading4's, the references, and contents and export them into word. I have
some code that does this already (I'll post at bottom), but it does this by
counting the paragraph styles. Which works to a point but sometimes,
invisibly people will leave in the odd header 3, or header 2, this screws up
the counting. Is there a better way of doing this?
The code is below, not in its entirity but enough to show you what its
doing.
'Reserve resource for database object called loerecord
'open a blank LOE recorder
' Set dbase = CurrentDb
For Each aparagraph In ActiveDocument.Paragraphs
'Extract document number from document
If aparagraph.Style = "Body Text" Then
If projnumfound = False Then
crPos = InStr(aparagraph, " ")
'docnum = Trim(Left$(aparagraph, crPos - 1))
projnumfound = True
End If
End If
'1111111111111111111111111111111111111111111111111111111111111111111111111111111111
'check on level number and dont print it until in section two
If aparagraph.Style.ListLevelNumber = 1 Then
If testCaseUnderPrep = True Then
testnum = document_no & " - " & onecounter & "." & twocounter &
"." & threecounter & "." & fourcounter
insert_data document_no, project_no, testnum, parah1, parah2,
parah3, parah4, refpara, testcase, testCaseUnderPrep, overwrite_duplicates,
dbase
End If
onecounter = onecounter + 1
twocounter = 0
threecounter = 0
fourcounter = 0
parah1 = aparagraph & " "
End If
'22222222222222222222222222222222222222222222222222222222222222222222222222222222222
If aparagraph.Style.ListLevelNumber = 2 Then
If testCaseUnderPrep = True Then
testnum = document_no & " - " & onecounter & "." & twocounter &
"." & threecounter & "." & fourcounter
insert_data document_no, project_no, testnum, parah1, parah2,
parah3, parah4, refpara, testcase, testCaseUnderPrep, overwrite_duplicates,
dbase
End If
twocounter = twocounter + 1
threecounter = 0
fourcounter = 0
parah2 = aparagraph & " "
End If
'3333333333333333333333333333333333333333333333333333333333333333333333333333333333If aparagraph.Style.ListLevelNumber = 3 Then If testCaseUnderPrep = True Then testnum = document_no & " - " & onecounter & "." & twocounter&"." & threecounter & "." & fourcounter insert_data document_no, project_no, testnum, parah1,parah2,parah3, parah4, refpara, testcase, testCaseUnderPrep,overwrite_duplicates,dbase End If threecounter = threecounter + 1 fourcounter = 0 parah3 = aparagraph & " " End If'44444444444444444444444444444444444444444444444444444444444444444444444444444444444 If aparagraph.Style.ListLevelNumber = 4 Then threeEncountered = False If testCaseUnderPrep = True Then testnum = document_no & " - " & onecounter & "." & twocounter&"." & threecounter & "." & fourcounter insert_data document_no, project_no, testnum, parah1,parah2,parah3, parah4, refpara, testcase, testCaseUnderPrep,overwrite_duplicates,dbase End If fourcounter = fourcounter + 1 parah4 = aparagraph & " " End If If aparagraph.Style = "TC_Reference" Then refpara = aparagraph & " " End If If aparagraph.Style = "Testcase" Then testCaseUnderPrep = True tmp_testcase = aparagraph testcase = testcase & tmp_testcase End IfNext ' MsgBox ("finishing") dbase.Close Set dbase = Nothing loerecord.CloseCurrentDatabase loerecord.Quit Set loerecord = Nothing MsgBox ("Finshed!")End SubCheersRod