Solved

# set a decimal tab using VBA

Posted on 2014-02-11
774 Views
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:

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
``````
0
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
• 2

LVL 51

Accepted Solution

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)
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
``````
EDIT used the with mytable

Regards
0

Author Comment

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

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

Regards, Andreas
0

## Featured Post

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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
Course of the Month2 days, 3 hours left to enroll