Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-16-2016, 01:54 AM
gmayor's Avatar
gmayor gmayor is offline Table style - first, last and odd column formatting issue Windows 10 Table style - first, last and odd column formatting issue Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 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
 

Tags
table styles



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table style - first, last and odd column formatting issue 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
Table style - first, last and odd column formatting issue How to globally change the formatting of a bullet style to another style? ravl13 Word 5 03-10-2013 05:04 PM
Table style - first, last and odd column formatting issue Combining 2 column style with 1 column style Don83 Word 1 10-18-2012 06:13 AM
Table style - first, last and odd column formatting issue magazine column style Nasser Word 4 04-21-2010 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:25 PM.


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