Solved

Avoiding selection object when setting a range on a table macro

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

705 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

18 Experts available now in Live!

Get 1:1 Help Now