Help with Pasting Tables from Excel to Word

bisel

Board Regular
Joined
Jan 4, 2010
Messages
233
Office Version
  1. 365
Platform
  1. Windows
Greetings all,

I have a macro in Excel that creates a Word document and inserts various objects from Excel to the Word document. Everything is working as I want except one thing.

In several instances, I am copying an Excel range and pasting into the Word document as a table. The paste is performed at a specific bookmark in the Word document. In my macro, I am trying to go back to two specific tables and set the column widths to the same for each of those two tables. This is how I would like the tables to come out ...
2023-05-30_10-02-24.jpg


After running my macro, this is how the tables appear ...
2023-05-30_10-07-06.jpg


I have tried to add some code to my macro, which seems to execute without any errors, however, there is no change in my tables appearance ...

VBA Code:
:
:
' Adjust Column Widths on Reserve Component Maint Schedule Tables

    With newWord.Tables(2) ' Table(2) should be the Completed Schedule Table
        .PreferredWidthType = wdPreferredWidthPercent
        .Columns(1).SetWidth ColumnWidth:=10
        .Columns(2).SetWidth ColumnWidth:=13
        .Columns(3).SetWidth ColumnWidth:=13
        .Columns(4).SetWidth ColumnWidth:=13
        .Columns(5).SetWidth ColumnWidth:=8
        .Columns(6).SetWidth ColumnWidth:=13
        .Columns(7).SetWidth ColumnWidth:=30
    End With
    
    With newWord.Tables(3) ' Table(3) should be the Maintenance Schedule table
        .PreferredWidthType = wdPreferredWidthPercent
        .Columns(1).SetWidth ColumnWidth:=10
        .Columns(2).SetWidth ColumnWidth:=13
        .Columns(3).SetWidth ColumnWidth:=13
        .Columns(4).SetWidth ColumnWidth:=13
        .Columns(5).SetWidth ColumnWidth:=8
        .Columns(6).SetWidth ColumnWidth:=13
        .Columns(7).SetWidth ColumnWidth:=30
    End With
    :
    :

What am I doing wrong?

Any help is greatly appreciated.

Steve
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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