#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
Quote:
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. |
Tags |
table styles |
Thread Tools | |
Display Modes | |
|
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 |