Solved

Avoiding selection object when setting a range on a table macro

Posted on 2007-04-02
2
127 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

786 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