read per line until the end of page

J

john smith

Hi,

I tried to read per line from my table of content in the document and write
it into the text file.
It's not working since it only read the first 3 lines and after that I
always get bad parameter message error.
Would anyone know how to read per line from the table of content until the
page break?
Please help me...!

Thank you so much...
John

Part II Test Cases 8

1 Central Management Console (CMC) 8

1.1 CMC Sanity Check 8

1.2 Folders 10

1.3 Crystal Report 18

1.3.1 Add Report 19

1.3.2 Preview Report 23

1.4 Program and 3rd Party Objects 29

1.4.1 Add Objects 29

1.4.2 Program Object Viewing. 31

1.5 Categories 33

1.5.1 Create Category. 34

1.5.2 Modify Category. 35

1.5.3 Delete Category. 37

1.5.4 Assign Category. 38

1.5.5 Move Category. 39

1.5.6 Apply Rights to Category. 41

1.6 Universe (Sanity) 42
--------------------------page break-----------------------

Sub readtableofcontent()
Dim oRngH As Word.Range
Dim NextLine As Integer
Set oRngH = ActiveDocument.Range
NextLine = 2

With oRngH.Find
.Text = "Part II Table of Content"
.Font.Name = "Verdana"
.Font.Size = 10
If .Execute Then
oRngH.Move wdParagraph, NextLine
While
(oRngH.Application.ActiveDocument.Paragraphs.Last.Range.Text <> Chr(11))
oRngH.Move NextLine
NextLine = NextLine + 1
oRngH.Expand wdParagraph
objFile.writeLine (oRngH.Text)
Wend
End If
End With
end sub
 
J

Jezebel

That's doing it the hard way. Why no just to find the TOC and write that to
your text file --

Dim pField As Word.Field
Dim pFilenum as long

'Iterate the fields in the document
For Each pField In ActiveDocument.Fields

'Find the TOC
If pField .Type = wdFieldTOC Then

'Write the TOC to the output file
pFileNum = Freefile
open "C:\.....\myfile.txt" for output as pFileNum
Print pFileNum, pField.Result
Close #pFileNum

Exit For
End If
Next
 
J

john smith

It's because i just want to get section 2 till the end of page. :(
Please help me Jezebel.

Thank you so much!
 
J

Jezebel

You'll need to explain that: you want the TOC plus everything that follows
up to the next hard page break; or you have a page break within the TOC? --
and if the latter, is it a manually inserted page break?
 
J

john smith

I want TOC from "part II Test Cases" until the end of the TOC.

If TOC go to next page then the page break will occur automatically.

Hope this make things clear.

Thank you so much for the help, Jezebel!
 
J

Jezebel

To extract from "part II Test Cases" until the end of the TOC --


Dim pField As Word.Field
Dim pFilenum as long
Dim pIndex as long
Dim pText as string

Const pFIND = "part II Test Cases"

'Iterate the fields in the document
For Each pField In ActiveDocument.Fields

'Find the TOC
If pField .Type = wdFieldTOC Then

'Get the TOC
pText = pField.Result

'Find "part II Test Cases"
pIndex = instr(pText, pFIND)
if pIndex = 0 then
... 'error: not found

else
pText = Mid$(pText, pIndex + len(pFIND)

'Write the TOC to the output file
pFileNum = Freefile
open "C:\.....\myfile.txt" for output as pFileNum
Print pFileNum, pText
Close #pFileNum

end if

Exit For
End If
Next
 

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