Excel VBA PreferredWidth on Word Table Columns

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
120
Office Version
  1. 2016
Platform
  1. Windows
Hello,

Using Excel VBA, I am trying to adjust the column widths of a table I created in Word. I have tried many variations of this, but I still cannot get this formatted correctly. Here is a snippet of the code I currently have:

VBA Code:
wrdDoc.Tables.Add Range:=.Range, NumRows:=4, NumColumns:=3, DefaultTableBehavior:=0

With wrdDoc.Tables(wrdDoc.Tables.Count)
                    .Columns.PreferredWidthType = wdPreferredWidthPercent
                    .Columns(1).PreferredWidth = 10
                    .Columns(2).PreferredWidth = 20
End With


With this particular version, the resulting table shows three columns, each of which has the same column width. I have tried wdPreferredWidthPoints as well, but that also does not display correctly.

Can you let me know if I am missing something? Perhaps there is a parameter I can add/change on the first line when I create the table? Perhaps there is another column attribute I can use besides PreferredWidth?

Any hints you can provide to help me correct this are greatly appreciated. Thank you!!!


Dennis
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do you have a reference set to the Word object library?
 
Upvote 0
Do you have a reference set to the Word object library?
I do. I use this script all the time. Now I am trying to add a new table to the Word document, and that's the part I am having problems with.

Thanks,
Dennis
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top