-
VBA logic help
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 [i.e., the one we just moved up to]
If intNewPrgOL >= intCurrentPrgOL, then move up to the previous paragraph, set intNewPrgOL = outline level of 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:
[vba] 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[/vba]
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
[vba]If intNewProgOL >= intCurrentPrgOL Then[/vba]
and
[vba]ElseIf intNewPrgOL < intCurrentPrgOL Then[/vba]
Can anyone see my mistake?
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules