Hello,

Allow me to quickly portray my problem. My figure captions are
formatted like this (example):

Figure 1-1: (inserted tabstop) The difference between ...
- The whole paragraph is formatted with a custom caption style
- The beginning up to the caption description itself (Figure
1-1:inserted tabstop) is formatted with a custom character style

Now I would like to reset the character style formatting of the
tabstop to the underlying custom caption style by using below macro.

It is working fine but I would like to avoid the "rng.select" line
because one should use ranges without having to select them, am I
right? How can I achieve this?


Sub ResetTabFormat()

Dim para As Word.Paragraph
Dim rng As Word.Range

Application.ScreenUpdating = False
For Each para In ActiveDocument.Paragraphs
If para.Range.Style.NameLocal = "custom_caption_style" Then

Set rng = para.Range

rng.StartOf unit:=wdParagraph
With rng
.MoveUntil Cset:=vbTab, Count:=wdForward
.MoveEnd unit:=wdCharacter, Count:=1
.Select 'How do I have to rewrite the macro not using "with
rng.select"
End With

rng.Font.Reset

End If
Next para

End Sub

Help is appreciated. Thank you in advance

Regards,

Andreas

Re: How to avoiding "rng.select" in a macro ? by Jonathan

Jonathan
Tue Feb 06 03:11:41 CST 2007

You only need to Select if you subsequently do something with the Selection
object. from the code that you have shown us, you don't. Just delete that
line.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



"andreas" <andreas.hermle@gmx.de> wrote in message
news:1170752203.673014.301280@v45g2000cwv.googlegroups.com...
> Hello,
>
> Allow me to quickly portray my problem. My figure captions are
> formatted like this (example):
>
> Figure 1-1: (inserted tabstop) The difference between ...
> - The whole paragraph is formatted with a custom caption style
> - The beginning up to the caption description itself (Figure
> 1-1:inserted tabstop) is formatted with a custom character style
>
> Now I would like to reset the character style formatting of the
> tabstop to the underlying custom caption style by using below macro.
>
> It is working fine but I would like to avoid the "rng.select" line
> because one should use ranges without having to select them, am I
> right? How can I achieve this?
>
>
> Sub ResetTabFormat()
>
> Dim para As Word.Paragraph
> Dim rng As Word.Range
>
> Application.ScreenUpdating = False
> For Each para In ActiveDocument.Paragraphs
> If para.Range.Style.NameLocal = "custom_caption_style" Then
>
> Set rng = para.Range
>
> rng.StartOf unit:=wdParagraph
> With rng
> .MoveUntil Cset:=vbTab, Count:=wdForward
> .MoveEnd unit:=wdCharacter, Count:=1
> .Select 'How do I have to rewrite the macro not using "with
> rng.select"
> End With
>
> rng.Font.Reset
>
> End If
> Next para
>
> End Sub
>
> Help is appreciated. Thank you in advance
>
> Regards,
>
> Andreas
>