Solved

Avoiding selection object when setting a range on a table macro

Posted on 2007-04-02
2
126 Views
Last Modified: 2010-04-30
Hello,
below macro applies a custom paragraph style from the second row to the last row of a selected table. Can this code be improved, e.g. by not using the  selection object when setting the range?
Help is appreciated. Thank  you very much in advance.

Sub ApplyStyleSecondToLastRow()
Selection.Tables(1).Select
Selection.SetRange _
        Start:=Selection.Rows(2).Range.Start, _
        End:=Selection.End
                 Selection.Style = "custom paragraph style"
End Sub
0
Comment
Question by:AndreasHermle
2 Comments
 

Author Comment

by:AndreasHermle
ID: 18841084
Hello,
found out myself. I guess this is the best way forward:

Sub ApplyStyleSecondToLastRow()
Dim tbl As Word.Table
Dim row As Word.row
Dim rng As Word.Range

   Set tbl = ActiveDocument.Tables(1)
   Set rng = tbl.Range

   For Each row In tbl.Rows
   rng.SetRange tbl.Rows(2).Range.Start, tbl.Rows.Last.Range.End
   
      rng.Style = "Dipl_Tbl_TK"
   Next row
End Sub
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 18978573
AndreasHermle,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now