Pro VB 6For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB 6 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
Another question:
I want to store the last heading before the caret position(insertionpoint) in a variable. I've done this by starting at the top of the document and search down to the caret(Selection.start) and check all the words on the way down. This works, but I think it would be easier and time saving to start at the caretposition in the text and search upwards in the text and store the first heading I meet. But is this possible to do? I really need help on this one!
here's my code so far:
'each word
Dim MyWord As Rang
'variable to store the sum of characters of the checked words
Dim number As Long
number = 0
'variable to store the number of characters from the beginning of
'the text to the caretposition
Dim number3
'Assigning the value
number3 = Selection.Start
'Checking each word until I'm at the caretposistion
For Each MyWord In ActiveDocument.Words
number = MyWord.Characters.Count + number
If number >= number2 Then
Exit For
End If
checking the style of the word
select case MyWord.Style
case "heading1"
store heading1.......
case "heading2"
store heading2.....
end select
Try this algorithm:
1. Select all text up to caret
2. Get the Paragraphs collection of Selection
3. For each Item backwards in Paragraphs collection:
1. Get Style of Item(i)
2. Test against each wdStyleHeadingx (x = Heading level number)