View Single Post
 
Old 06-29-2011, 05:51 AM
flds flds is offline Windows XP Office 2007
Novice
 
Join Date: Apr 2011
Posts: 27
flds is on a distinguished road
Default

Hi Paul,
Thanks for your reply.

"Re blank pages in the tables document, that suggests your source document has manual page breaks as well as Section breaks. Please confirm. If so, I can modify the code to remove them. The code:"

Yes there may or may not be manual page breaks and section breaks. They need to be removed.

"should delete all tables from the source document once the tables document is created and before going on to the appendices document's creation. If any remain when the appendices & refernces documents are created, that suggests there are tables in textboxes or something such. Please confirm."

As far as I see I doubt that tables are in text boxes, the documents I opened i have not come across any.

"Re appendices document, the lack of output suggests the first word of the relevant Section is not 'Appendix'. The 'If UCase(Sctn.Range.Words.First) = "APPENDIX" Then' test captures any combination of upper/lower case, by converting everything to upper case and comparing on that basis."

Appendix A, Appendix B, Appendix C etc. are separate in a line, following lines contain the text.

"Re references document, the inclusion of the appendices is due to whatever causes the appendices not to be extracted beforehand."

Appendixes is the last section in the documents. I dont know why appendix is copied under references.

"Re the 'Design Requirements', does this heading begin an new Section? How does one detect when that portion of the document has ended (eg end of the Section in which the heading appears, start of 'references' Section, something else)? "

Yes it begins a new section (ie. 2. DESIGN REQUIREMENTS) The new section will start as section 3. ????

"I have no idea which code from the link you posted relates to this - it all seems to be directed at converting vba code to Visual Studio."

I mentioned it as Tip# 5, anyway I have copied the code below.



Tip #5: Convert Existing VBA Code
Code:
Code:
 
PublicSub CreateOutline()
Dim docOutline As Word.Document
Dim docSource As Word.Document
Dim rng As Word.Range
 
Dim astrHeadings AsVariant
Dim strText AsString
Dim intLevel AsInteger
Dim intItem AsInteger
 
Set docSource = ActiveDocument
Set docOutline = Documents.Add
 
' Content returns only the
' main body of the document, not
' the headers and footer.
Set rng = docOutline.Content
astrHeadings = _
docSource.GetCrossReferenceItems(wdRefTypeHeading)
 
For intItem = LBound(astrHeadings) To UBound(astrHeadings)
' Get the text and the level.
strText = Trim$(astrHeadings(intItem))
intLevel = GetLevel(CStr(astrHeadings(intItem)))
 
' Add the text to the document.
rng.InsertAfter strText & vbNewLine
 
' Set the style of the selected range and
' then collapse the range for the next entry.
rng.Style = "Heading " & intLevel
rng.Collapse wdCollapseEnd
Next intItem
EndSub
 
PrivateFunction GetLevel(strItem AsString) AsInteger
' Return the heading level of a header from the
' array returned by Word.
 
' The number of leading spaces indicates the
' outline level (2 spaces per level: H1 has
' 0 spaces, H2 has 2 spaces, H3 has 4 spaces.
 
Dim strTemp AsString
Dim strOriginal AsString
Dim intDiff AsInteger
 
' Get rid of all trailing spaces.
strOriginal = RTrim$(strItem)
 
' Trim leading spaces, and then compare with
' the original.
strTemp = LTrim$(strOriginal)
 
' Subtract to find the number of
' leading spaces in the original string.
intDiff = Len(strOriginal) - Len(strTemp)
GetLevel = (intDiff / 2) + 1
EndFunction
Thanks
FLDS
Reply With Quote