PDA

View Full Version : MoveEndUntil that scans for paragraph format



oerjan
11-25-2015, 02:53 AM
Hi,

First posting here. I´m rather new to VBA. Pls bear with me.

I would like to extend a range of paragraphs until the range meets a paragraph with a certain formatting (ParagraphFormat.KeepWithNext = -1)

I have found the method MoveEndUntil but the parameter Cset only scans for characters.

Is there a way to solve this?

TIA
Örjan

gmaxey
11-25-2015, 08:08 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = Selection.Paragraphs(1).Range
Do
oRng.MoveEnd wdCharacter, 1
Loop Until oRng.Characters.Last.Next.Paragraphs(1).KeepWithNext = True
oRng.Select
lbl_Exit:
Exit Sub
End Sub

oerjan
11-25-2015, 08:33 AM
Hey Greg,

Thanks a lot. Works great! :-)

Best regards
Örjan

PS. The label?

gmaxey
11-25-2015, 08:52 AM
lbl_Exit:
Exit Sub

Is just personal style and a canned feature in 99% of my code. If nothing else, to me it serves as sort of an indicator that I've reviewed/tested the code. Used in conjunction with an error handler:

Err_Hander:
'Do whatever
Resume lbl _Exit: