View Single Post
 
Old 08-16-2016, 01:54 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote