Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Pro VB 6 For 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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 30th, 2003, 06:54 AM
Registered User
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Old August 18th, 2003, 04:22 AM
Registered User
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

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)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Document to PDF BSkelding ASP.NET 1.0 and 1.1 Professional 2 July 19th, 2013 04:53 AM
Finding End of Document Larry Landis Word VBA 1 September 11th, 2007 11:31 PM
how to finding the Graphic objects in word doc madhan_needs_help Word VBA 2 August 8th, 2007 10:38 AM
Urgent: Finding meanings of a word using VBA SMI Word VBA 2 March 26th, 2007 08:13 AM
Checkbox on word document kareltje Excel VBA 3 February 17th, 2005 11:17 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.