Finding a heading in a word document
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
Next MyWord
|