Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Avoiding selection object when setting a range on a table macro

Posted on 2007-04-02
2
Medium Priority
?
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Suggested Courses

609 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