AKK
07-25-2007, 10:49 AM
Hi --
My question has less to do with actual syntax and more to do with the logical order that VBA uses to carry out loops & decision making statements. I've written what I thought made sense, but something isn't working right.
Here is the logical process I want VBA to go through, in (mostly) plain English:
Set intCurrentPrgOL = outline level of current paragraph
Move up to previous paragraph.
Set intNewPrgOL = outline level of new current paragraph
If intNewPrgOL >= intCurrentPrgOL, then move up to the previous paragraph, set intNewPrgOL = outline level of [I]that paragraph, and check again.
If intNewPrgOL < intCurrentPrgOL, then go to the end of the line & change the [u] tag to a [Z] tag [all the ends of my lines have little tags like this]
If intNewPrgOL <> 1, then move up to previous paragraph, and start the WHOLE process over again.
If intNewPrgOL = 1, we're done for now.
And here's the code that I thought would do that:
Do Until intNewPrgOL = 1
If intNewProgOL >= intCurrentPrgOL Then
Selection.MoveUp Unit:=wdParagraph, Count:=1
intNewPrgOL = Selection.Paragraphs(1).OutlineLevel
ElseIf intNewPrgOL < intCurrentPrgOL Then
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:="Z"
Selection.MoveUp Unit:=wdParagraph, Count:=2
intNewPrgOL = Selection.Paragraphs(1).OutlineLevel
End If
Loop
But it always ends up changing the first few tags correctly, and then ending up in a paragraph with outline level 10 (normal text) & switching back and forth between the line
If intNewProgOL >= intCurrentPrgOL Then
and
ElseIf intNewPrgOL < intCurrentPrgOL Then
Can anyone see my mistake?
Thanks!
My question has less to do with actual syntax and more to do with the logical order that VBA uses to carry out loops & decision making statements. I've written what I thought made sense, but something isn't working right.
Here is the logical process I want VBA to go through, in (mostly) plain English:
Set intCurrentPrgOL = outline level of current paragraph
Move up to previous paragraph.
Set intNewPrgOL = outline level of new current paragraph
If intNewPrgOL >= intCurrentPrgOL, then move up to the previous paragraph, set intNewPrgOL = outline level of [I]that paragraph, and check again.
If intNewPrgOL < intCurrentPrgOL, then go to the end of the line & change the [u] tag to a [Z] tag [all the ends of my lines have little tags like this]
If intNewPrgOL <> 1, then move up to previous paragraph, and start the WHOLE process over again.
If intNewPrgOL = 1, we're done for now.
And here's the code that I thought would do that:
Do Until intNewPrgOL = 1
If intNewProgOL >= intCurrentPrgOL Then
Selection.MoveUp Unit:=wdParagraph, Count:=1
intNewPrgOL = Selection.Paragraphs(1).OutlineLevel
ElseIf intNewPrgOL < intCurrentPrgOL Then
Selection.EndKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:="Z"
Selection.MoveUp Unit:=wdParagraph, Count:=2
intNewPrgOL = Selection.Paragraphs(1).OutlineLevel
End If
Loop
But it always ends up changing the first few tags correctly, and then ending up in a paragraph with outline level 10 (normal text) & switching back and forth between the line
If intNewProgOL >= intCurrentPrgOL Then
and
ElseIf intNewPrgOL < intCurrentPrgOL Then
Can anyone see my mistake?
Thanks!