Outline view loop

C

carim.fam

Hi,

So far I have managed to indivudually promote or demote a line, but I
cannot generalize zhis macro to the whole document ...

Sub MacroAdjust()
Dim StrWord As String 'text being analysed
Dim NPer As Long 'number of periods
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If InStr(Selection, ".") = 0 Then
Selection.Paragraphs.OutlinePromote
Else
StrWord = Left(Selection, InStr(Selection, " ") - 1)
NPer = UBound(Split(StrWord, ".")) - LBound(Split(StrWord, "."))
Select Case NPer
Case 2: Selection.Paragraphs.OutlineDemote
Case 3: Selection.Paragraphs.OutlineDemote
Selection.Paragraphs.OutlineDemote
End Select
End If
End Sub

Is there a way to loop through all the headings shown in the outline
view ?
Thanks in advance for your advice
Cheers
Carim
 
C

Cindy M -WordMVP-

So far I have managed to indivudually promote or demote a line, but I
cannot generalize zhis macro to the whole document ...

Sub MacroAdjust()
Dim StrWord As String 'text being analysed
Dim NPer As Long 'number of periods
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If InStr(Selection, ".") = 0 Then
Selection.Paragraphs.OutlinePromote
Else
StrWord = Left(Selection, InStr(Selection, " ") - 1)
NPer = UBound(Split(StrWord, ".")) - LBound(Split(StrWord, "."))
Select Case NPer
Case 2: Selection.Paragraphs.OutlineDemote
Case 3: Selection.Paragraphs.OutlineDemote
Selection.Paragraphs.OutlineDemote
End Select
End If
End Sub

Is there a way to loop through all the headings shown in the outline
view ?
Based only on what you show us, I'd say take a look at the
Selection.MoveDown method (related to the EndKey method you already
have in your code). This will return the actual number of units
(wdLine) that you moved. When it returns 0, you'd be at the end of the
visible text. Roughly, I'd set your code up like this (untested):

Do
'The code you have comes here
Loop While Selection.MoveDown(wdLine, 1) > 0

Note that you may need to adjust selecting the entire line by first
moving the Selection to the front of the current line before extending
it across the line (something like Selection.HomeKey wdLine)

Note: the better place to get help with macros would be the word.vba
newsgroup. This is an end-user group, which means people with macro
knowledge may not happen by as often as in a vba group.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

carim.fam

Hello Cindy,

Thanks a lot for your piece of advice.

As far as the newsgroup is concerned, sorry for the inconvenience, I
will adjust right away.
As a matter of fact, it is my very first attempt in word.vba ... the
little I know comes from Excel.

Again thanks for your help
Best Regards
Carim
 
C

Cindy M -WordMVP-

As far as the newsgroup is concerned, sorry for the inconvenience, I
will adjust right away.
Not an inconvenience :) Just that you're more likely to get help more
quickly in a word.vba group than here.
As a matter of fact, it is my very first attempt in word.vba
Good luck, then :)! And one small tip, in that case: as in Excel, the
macro recorder is good for telling you the names of the objects you
need to work with. But the code is generally less than reliable
(SELECTION, like Selection or ActiveCell in Excel). If possible, it's
always a good idea to convert from Selection to using a Range object
(again, just like Excel). This is more easily said than done, I
realize :) But something to think about. In the case of your
particular macro, Selection is fine because only a Selection can deal
with lines.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

carim.fam

Cindy,

May I thank you for your tips and advice. You are very kind, and your
encouragements are my best reward ... :)
Indeed I badly need them, as I will soon have to understand the
"multiple-items-per-condition" challenge ..!!!

Thanks again and Best regards
Carim
 
C

Cindy M -WordMVP-

Indeed I badly need them, as I will soon have to understand the
"multiple-items-per-condition" challenge ..!!!
<ouch> (Personally, I consider it fun, but I've been accused of
having an odd sense of humour.)

There's a discussion on my website, in case you haven't come
across it yet, with links to sample files. If the DATABASE field
approach meets your needs, it's by far the easiest to work with.

If you need the more sophisticated, coded approach the
WdAcc97.zip file can give you some basics. Apply these to using
an ADO connection in order to pull the data from Excel. Should be
(relatively) easy :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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