![]() |
|
|
|
#1
|
||||
|
||||
|
Just for fun, I setup 1500 copies of your table and while you cannot process a column range, you can select a column and process a selection, so the following VBA code will process the first and last columns to add named styles to those columns.
I also added a progress indicator (which will slow the process marginally) and the code below took 3 minutes and 40 seconds to complete in Word 2016 (2 minutes 27 seconds in Word 2007, 2 minutes 11 second in Word 2010). This is clearly faster than processing the individual cells. You can download the progress bar from http://www.gmayor.com/Zips/ProgressBar.zip Code:
Sub Macro1()
Dim ofrm As New frmProgress
Dim PortionDone As Double
Dim i As Long
Dim StartTime As Double
Dim MinutesElapsed As String
Selection.HomeKey wdStory
ActiveDocument.Range.Style = "Normal"
ActiveDocument.Range.ParagraphFormat.Reset
ActiveDocument.Range.Font.Reset
Application.ScreenUpdating = False
ofrm.Show vbModeless
StartTime = Timer
For i = 1 To ActiveDocument.Tables.Count
PortionDone = i / ActiveDocument.Tables.Count
ofrm.lblProgress.Width = ofrm.fmeProgress.Width * PortionDone
ofrm.Caption = "Processing Table " & i - 1 & " of " & ActiveDocument.Tables.Count
ActiveDocument.Tables(i).Columns(1).Select
Selection.Style = "Heading 2"
ActiveDocument.Tables(i).Columns(3).Select
Selection.Style = "Heading 1"
DoEvents
Next i
Unload ofrm
Application.ScreenUpdating = True
MinutesElapsed = Format((Timer - StartTime) / 86400, "hh:mm:ss")
MsgBox "This code ran successfully in " & MinutesElapsed, vbInformation
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Tags |
| table styles |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Table formatting- column widths to percent
|
dherr | Word VBA | 3 | 05-02-2023 09:37 AM |
| VBA Word Table - Select More than 1 Column at a time - Apply Formatting | jc491 | Word VBA | 12 | 09-24-2015 06:03 AM |
How to globally change the formatting of a bullet style to another style?
|
ravl13 | Word | 5 | 03-10-2013 05:04 PM |
Combining 2 column style with 1 column style
|
Don83 | Word | 1 | 10-18-2012 06:13 AM |
magazine column style
|
Nasser | Word | 4 | 04-21-2010 02:41 PM |