Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2015, 10:03 AM
dherr dherr is offline Table formatting- column widths to percent Windows 8 Table formatting- column widths to percent Office 2007
Advanced Beginner
Table formatting- column widths to percent
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default Table formatting- column widths to percent

Hi,
I want to set the columns of a table to procentual values and have written the following code:
Code:
Sub setProz(tb As Word.table, prozentual As Variant)
    Dim i As Integer, co As Integer
    With tb
        .PreferredWidthType = wdPreferredWidthPercent
        co = .columns.Count
        For i = 0 To co - 1
            .columns(i + 1).PreferredWidth = Val(prozentual(i))
        Next
    End With
End Sub
The parameters are first a table, second an array, for instance
Array(10, 50, 20, 20) when the table has 4 columns.
The problem is when I use this code, the table doesn't change the column widths at normal runtime.
When I set a debugging breakpoint to the line 'End Sub' the table changes after a second.
I tried to 'refresh' or 'update' the table, but no success...
What's to do?

Regards-


Dietrich
Reply With Quote
  #2  
Old 03-17-2015, 03:22 PM
gmaxey gmaxey is offline Table formatting- column widths to percent Windows 7 32bit Table formatting- column widths to percent Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,204
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

I called your code using the following and it worked fine:

Code:
Sub Test()
  Dim arrPercent() As String
  arrPercent = Split("10,50,20,20", ",")
  setProz ActiveDocument.Tables(1), arrPercent
End Sub
Reply With Quote
  #3  
Old 03-17-2015, 03:50 PM
dherr dherr is offline Table formatting- column widths to percent Windows 8 Table formatting- column widths to percent Office 2007
Advanced Beginner
Table formatting- column widths to percent
 
Join Date: Nov 2014
Location: Austria
Posts: 45
dherr is on a distinguished road
Default

Thanks for your answer, Greg,
when I use your advice I have the same effect. So my code is OK.

Again: the problem is, that the table shows right only then when I set this breakpoint during debugging; I think because of the pause (the table has 300 rows). When I delete this breakpoint the table changes NOT to the new column widths.
It seems to me that because of the breakpoint the table 'has time' to 'refresh' and shows new columns width. Otherwise, without breakpoint, not.

Something new:
Today I have set a STOP (VBA order, not a breakpoint) after my setProz routine and the table changes the column widths... astonishing.
But now I have a new problem: How to continue the code after the STOP ???

Regards
Dietrich

Last edited by dherr; 03-18-2015 at 01:19 AM.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting one column into two with two different widths officeboy09 Excel 6 12-15-2013 09:48 PM
Adjusting column widths norwood Word VBA 0 09-24-2013 06:53 AM
Table formatting- column widths to percent VBA code to fix column widths molesy Excel 3 09-16-2013 12:51 PM
Table formatting- column widths to percent Alternate Table Column Widths on even and odd pages robrastelli Word 4 08-08-2012 07:33 PM
Table formatting- column widths to percent Altering Column Widths on Two Col Page abrogard Word 2 12-30-2010 06:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:35 PM.


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