Where am I???

B

Bill E.

I could really use some help on this one!! Any suggestions
would be really appreciated.

Here's the task and the existing code.

Task: Locate in the document all "charcter" styles that
are in use. Record the found "paragraphs" in an array for
later use.

Existing Code: This works, it's unacceptable because of
the speed issue. (It's God Awful Slow).

-----------------------------------------------------------
---------------------
With ActiveDocument.Styles
For lngI = 1 To .Count
If .Item(lngI).Type = wdStyleTypeCharacter Then
strCharStyle = .Item(lngI)
If .Item(lngI).InUse Then
With ActiveDocument.Content.Find
.Style = strCharStyle
' Loop through to denote all
paragraphs that contain
' this style.
Do While .Execute(FindText:="",
Forward:=True, _
Format:=True) = True
' If we found it...
If .Found = True Then
.Parent.Select
For lngJ = 1 To
ActiveDocument.Paragraphs.Count
If Selection.InRange( _

ActiveDocument.Paragraphs(lngJ).Range) _
Then
' Record the
location of the paragraph
' with the
character style.

arrCharacterstyleParas(lngJ) = True
Exit For
End If
DoEvents
Next
End If
Loop
End With
End If
End If
Next
End With
-----------------------------------------------------------
---------------------



The problem is that once we've found a character style in
use in the document we have to determine which paragraph
in the paragraphs collection it's in. The only way I've
found to do this is to iterate through the entire
paragraphs collection testing selection.inrange() for each
until we found it.

Please, someone help. I'm dyin here.....

Bill
 
B

Bill E

Thanks Jonathan, that was exactly what I needed.
-----Original Message-----
Hi Bill,

The slow part is almost certainly identifying the index number of the
paragraph. This article shows you how to do it much more quickly, with just
one line of code!

Determine the index number of the current paragraph, table, section ...
http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.h tm

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com





.
 

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