Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2016, 10:07 AM
BartS BartS is offline Table style - first, last and odd column formatting issue Windows 8 Table style - first, last and odd column formatting issue Office 2007
Novice
Table style - first, last and odd column formatting issue
 
Join Date: Aug 2016
Posts: 2
BartS is on a distinguished road
Angry Table style - first, last and odd column formatting issue

Hi,
I'm having an issue with table style. I want to apply different font size, style and color to first, last and odd columns.
While editing column style, preview window is showing exactly what I've formatted, but style is not applied correctly in document.
Table (3 col x 40 rows) is a list of words. I want [word], [phonetics] and [meaning] columns to be formatted differently.

Since I'm writing a file from python docx module, I can apply different paragraph style for each paragraph in each cell - no problem here.


For performance sake I though that I could format table columns and skip formatting paragraphs. For small file (up to 30 pages) i got 40% processing time reduction and for large files (roughly 150 pages+) I got 10% reduction. Absolute difference is small (max 20 sec) but I got mightily annoyed by the fact that Word doesn't cooperate.

Reformatting paragraph in a cell to normal seems to help for first column but not for other. And manual work is not an option as there will be more than 1500 tables in a document.

Can you suggest why would Word not cooperate and how to fix it. I'm using ms word 2007 on win 8.

Best regards
Bart
Attached Files
File Type: docx test failed table style last column.docx (11.1 KB, 12 views)
Reply With Quote
  #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,101
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
  #3  
Old 08-16-2016, 04:10 AM
BartS BartS is offline Table style - first, last and odd column formatting issue Windows 8 Table style - first, last and odd column formatting issue Office 2007
Novice
Table style - first, last and odd column formatting issue
 
Join Date: Aug 2016
Posts: 2
BartS is on a distinguished road
Default

Quote:
gmayor
Thx, for the code but I don't want to post process it in the word.
I'm writing the file from Python using docx module because its many time faster. Just to create all the tables and fill them with data, it was taking around 20 min in VBA - lots of pictures inserting and resizing (with file hidden, screen updating off etc). Same thing can be done from Python in max 3 min with all the formatting in place. If I could format table instead of cells it would take 2 min 40 s.

As you can see, time wise it doesn't really matter. I'm just curious why formatting table style might not work. Is this issue with word 2007? or multiple column formatting is a known issue? - I don't think so, since built in styles are heavily formatted.
Reply With Quote
Reply

Tags
table styles

Thread Tools
Display Modes


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 05:26 AM.


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