Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-03-2015, 08:38 AM
jc491's Avatar
jc491 jc491 is offline Windows 7 64bit Office 2013
VBA Novice
 
Join Date: Sep 2015
Location: UK
Posts: 55
jc491 is on a distinguished road
Default VBA Word - Format ALL Tables - Apply Specific Formatting to Sets of Columns – Font, Border & Width

Hi,
I hope everyone is well.
I am looking for some advice from the VBA experts.
I apologize if this has a complete solution elsewhere I have not been able to find it.

I have word documents that will contain a number of tables.
Each table may contain up to 15 columns.
If a table contains less columns I can delete a column from the final code.

I would like to format them in a specific way

Columns 1,2,4,6,7,9,10,12
· Font Size 2


· Font Color White
· Border Color White
· Column Width = 20px

Columns 2,5,8,11
· Font Size 12
· Font Color - Black
· Border Color Dark Grey
· Column Width = 150px


I know that I could run 2 separate macros – I would end up with a long page of code for each column.
However, I would like to learn how to do it in one - as I have a lot of documents to convert.
I have tried to fiddle about and searched online documentation but am not closer to a solution.

My attempt at putting together the concept,

Column Sizes
Code:
      For Each Table In ActiveDocument.Tables
      On Error Resume Next
      Table.Columns(1).Width = 20
      Table.Columns(2).Width = 20
  Table.Columns(4).Width = 20
  Table.Columns(6).Width = 20
                                etc
      On Error GoTo 0
    Next
  End Sub
Formatting the Columns

Code:
  Dim Table As Table, Cell As Cell
  Dim col as column
  For Each Table In ActiveDocument.Tables
  For Each Cell In Table.Range.Cells
   For Each Cell In .Columns(1).Cells
  Cell.Width = 20px
  Cell.Range.Font.Name = "Arial"
  Cell.Range.Font.Size = 2
  Cell.Range.Font.ColorIndex = white
   Cell.border.color =white
       
  Next Cell or column
      Next Table
      End Sub
I have managed to confuse myself - and am making errors. Also they are separate macros - I'm not sure how to combine them.

I would appreciate some help.

To Recap.
I need to Format all the Tables in a document, that have various number of columns.


Columns 1,2,4,6,7,9,10,12

· Font Size 2
· Font Color White
· Border Color White
· Column Width = 20px
These columns have ids and codes in them hence trying to give them a hidden appearance.



Columns 2,5,8,11 - Normal Columns
· Font Size 12
· Font Color - Black
· Border Color Dark Grey
· Column Width = 150px


I would be really grateful if an expert can guide me.

Thanking you in advance for your kind help and time.

J
Reply With Quote
 

Tags
table, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to apply formatting(color & shading) to specific letters in whole doc. (arabic) loopseye Word 3 08-05-2013 10:49 PM
How to set a custom border width in Word 2011 for Mac kchappell Word 0 11-10-2012 11:59 AM
Apply font color programatically using VBA Word divakarganta Word VBA 3 08-08-2012 08:05 PM
Formatting multiple tables and columns efficiently? table_column Word Tables 1 07-02-2012 05:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft