[powershell] Pasting table from Excel to Word, autofit table

Pater

New Member
Joined
Jan 13, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Currently working on a robot where I want to download an excel file from a system, copy paste the contents of the excel file to a word file as an embedded excel table, but the table is wider than the page (it is already in landscape mode). I am using a powershell script in DAS to execute this step. To solve the problem normally, I would simply right-click on the table and use Autofit -> Fit to Window. How do I do this in powershell?

My script is currently like this:

$destination = 'C:\Users\Pater\Downloads\archive2.docx' $word = new-object -comobject Word.application $word.visible = $true $doc1 = $word.documents.open($destination) $bookmark1 = $doc1.Bookmarks.Item("FacilitySheet") $xl = New-Object -comobject Excel.Application $xl.Visible = $true $xl.DisplayAlerts = $False $wb = $xl.Workbooks.Open("C:\Users\Pater\Downloads\spreadsheet.xlsx") $ws = $wb.ActiveSheet $Range1 = $ws.UsedRange.Cells $RowCount = $Range1.rows.count $CopyRange = $ws.Range("A1:O$RowCount").Copy() $bookmark1.Range.Paste()
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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