Style Problem

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
 
R

Rod Makin

I was thinking of maybe using the Table of Contents to do exactly what I
want but I dont know whether or indeed HOW to extract the text from the TOC?
Any ideas?

Oh and below, Im actually exporting to Access not Word. And that particular
leg of the process works fine.

Regards



Rod
 
C

Charles Kenyon

You can convert the TOC field to text by selecting it and pressing the
Ctrl-6 key combination. What you can do with it from there with code, I
don't know.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
D

Daiya Mitchell

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?
Maybe start the code with a Find&Replace operation that reduces multiple
paragraph marks to 1, to get rid of the empty paragraphs?
 

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