Solved

set a decimal tab using VBA

Posted on 2014-02-11
3
705 Views
Last Modified: 2014-02-11
Dear Experts:

I would like to insert a decimal tab at 1.7 cm in all cells of Column 2 and 3 (starting from row 2) of the currently selected table using VBA. I would like to get this code snippet integrated into an already existing macro.

That is what the macro recorder came up with:
'Selection.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(1.7) _
'        , Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces



Help is very much appreciated. Thank you very much in advance.

Regards,  Andreas


Sub Format_Columns_Add_Decimal_tabs_selected_table()

'to be expanded by inserting a decimal tab at 1.7 cm in all cells starting from row 2 of Column 2 and 3


Dim mytable As Table

Set mytable = Selection.Tables(1)
    With mytable
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
       .Columns(2).Width = CentimetersToPoints(3.1)
       .Columns(3).Width = CentimetersToPoints(3.1)
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
    End With
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39849541
Hi,

pls try

Sub Format_Columns_Add_Decimal_tabs_selected_table()

'to be expanded by inserting a decimal tab at 1.7 cm in all cells starting from row 2 of Column 2 and 3


Dim mytable As Table
Set d = ActiveDocument
Set mytable = Selection.Tables(1)
    With mytable
        For IdxRow = 2 To .Rows.Count
            For IdxCol = 2 To 3
                Set c = .Cell(IdxRow, IdxCol)
                c.Range.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(1.7) _
                    , Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces
            Next
        Next
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
       .Columns(2).Width = CentimetersToPoints(3.1)
       .Columns(3).Width = CentimetersToPoints(3.1)
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
    End With
End Sub

Open in new window

EDIT used the with mytable

Regards
0
 

Author Comment

by:AndreasHermle
ID: 39849553
Hi Rgonzo,

works like a charm. Thank you very much for your swift and professional help.

I deleted 'stop' on line 15. I am sure you placed this just for testing, am I right?

I will post a similar question soon.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 39849555
Rgonzo, as always, very professional and superb support. Thank you very much for it.

Regards, Andreas
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

Suggested Solutions

Title # Comments Views Activity
Ability to store text on the iPad? 10 73
Printing issues with color, black and white and MS WORD 19 63
How to check if an MS Word is closed in C# 21 91
Printing A1 on A4 Printer 8 109
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
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.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

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

19 Experts available now in Live!

Get 1:1 Help Now