A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

formatting tables in a document



 
 
Thread Tools Display Modes
  #1  
Old December 25th, 2008, 12:45 AM posted to microsoft.public.word.tables
Dina
external usenet poster
 
Posts: 54
Default formatting tables in a document

Hi,

I would like to know how to use VB editor to select and format all the
tables in a long document. I want to do the following:

Select the tables
Remove all the borders (they are now set to show borders on all sides of
each cell)
Hide all gridlines
Change the default cell margins to 0.00"
Change the column widths - the third column has to be 1" wide, and the
fourth column has to be 5" wide. There are five columns in each table.
Remove the first two and last columns

Is there any way to do this without selecting and changing each table
individually? Is any part of this possible to do?

The other way I can accomplish what I need to do is the following:

Select all the tables
Remove the first two and last column (keeping only the third and fourth
columns)
Convert the tables to text with the following specifications:
The paragraph formatting is set to Hanging by 1"
However, the other text in the document (that did not start out in tables)
will not be formatted this way.

This second way will make the final outcome look the same, so I can do it
this way as well.

Any input will be appreciated!

Thanks!


  #2  
Old December 25th, 2008, 01:57 AM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,488
Default formatting tables in a document

On Wed, 24 Dec 2008 16:45:00 -0800, Dina wrote:

Hi,

I would like to know how to use VB editor to select and format all the
tables in a long document. I want to do the following:

Select the tables
Remove all the borders (they are now set to show borders on all sides of
each cell)
Hide all gridlines
Change the default cell margins to 0.00"
Change the column widths - the third column has to be 1" wide, and the
fourth column has to be 5" wide. There are five columns in each table.
Remove the first two and last columns

Is there any way to do this without selecting and changing each table
individually? Is any part of this possible to do?

The other way I can accomplish what I need to do is the following:

Select all the tables
Remove the first two and last column (keeping only the third and fourth
columns)
Convert the tables to text with the following specifications:
The paragraph formatting is set to Hanging by 1"
However, the other text in the document (that did not start out in tables)
will not be formatted this way.

This second way will make the final outcome look the same, so I can do it
this way as well.

Any input will be appreciated!

Thanks!


Hi Dina,

The macro below will do what you asked.

When dealing with objects in a Word document through VBA, it's almost never
necessary to "select" anything. Instead, you refer to an object (such as a Table
object) that represents the thing in the document.

As noted in the comment, turning off the gridlines isn't permanent because it
isn't a property that's saved in the document file. If the document is opened on
another computer where the gridlines option is turned on, the gridlines will
show there.

Sub ReformatTables()
Dim oTbl As Table

' this is effective only for the current session
ActiveDocument.ActiveWindow.View.TableGridlines = False

For Each oTbl In ActiveDocument.Tables
If oTbl.Columns.Count = 5 Then
With oTbl
.Columns(5).Delete
.Columns(2).Delete
.Columns(1).Delete

.Columns(1).Width = InchesToPoints(1)
.Columns(2).Width = InchesToPoints(5)
.LeftPadding = 0
.RightPadding = 0
.Borders.OutsideLineStyle = wdLineStyleNone
.Borders.InsideLineStyle = wdLineStyleNone
End With
Else
MsgBox "Wrong number of columns in " _
& "table on page " & oTbl.Range _
.Information(wdActiveEndAdjustedPageNumber)
End If
Next
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:20 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.