Different table columns size in two Word versions using PreferredWidthType and PreferredWidth in VBA

Lauro Colasanti 121 Reputation points
2023-06-09T22:02:55.57+00:00

Hi,

I have the same VBA code to create a table and to set the size of its columns. The following:

Public Sub Test()
   Dim objTabella As Table
   Dim rng As Range
   
   Set objTabella = ActiveDocument.Tables.Add(Selection.Range, NumRows:=1, NumColumns:=2, _
               DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
               
    With objTabella
      .PreferredWidthType = wdPreferredWidthPercent
      .PreferredWidth = 100
      .Columns.PreferredWidthType = wdPreferredWidthPercent
      .Columns(1).PreferredWidth = 5
      .Columns(2).PreferredWidth = 95
    End With
End Sub

In Microsoft® Word per Microsoft 365 MSO (Versione 2305 Build 16.0.16501.20074) a 64 bit (on Windows 10 Home),

I get, as expected:

word

But in Microsoft® Word per Microsoft 365 MSO (Versione 2306 Build 16.0.16529.20000) a 64 bit (on Windows 11 Pro), the whole table is no more 100%, what I get is the following:

word 2

For both versions I have the Beta Channel Insider.

Do you have any idea why?

Thanks, Lauro

Microsoft 365 and Office Development Other
Microsoft 365 and Office Word For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Stefan Blom 2,861 Reputation points MVP Volunteer Moderator
    2023-06-13T08:51:19.9433333+00:00

    Since you are using beta/preview versions, you may have encountered a new bug. You should report it to Microsoft using the feedback facility in Word.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.