# Off Topic > Hello..Introduce yourself >  >  Fit a table (rows) from excel in Word using VBA

## Isa-T

Hi,

I'm trying to fit a table ex. from A to U, but the space is not enough for all the rows.
I'm using:
wdApp.AutoFitBehavior wdAutoFitWindow

but is not working and I don't know what I'm missing...  :Confused: 
The VBA code is:
Sub test()

Dim wdApp As Object
Dim wd As Object

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then
    Set wdApp = CreateObject("Word.Application")
    End If
On Error GoTo 0

Set wd = wdApp.Documents.Open("test.docx")

wdApp.Visible = True

Sheets("COVER SHEETS").Select
Range("A1:H37").Copy
wdApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
wdApp.AutoFitBehavior wdAutoFitWindow
wdApp.Selection.InsertBreak Type:=7


Sheets("COVER SHEETS").Select
Range("A38:H69").Copy
wdApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
wdApp.Selection.InsertBreak Type:=7

Sheets("COVER SHEETS").Select
Range("A70:H93").Copy
wdApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
wdApp.Selection.InsertBreak Type:=7

Sheets("TEST PROCEDURE").Select
Range("B1:U298").Copy
wdApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
wdApp.Selection.InsertBreak Type:=7

End Sub

----------


## arlu1201

Hello Isa-T, 

Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.

----------


## Isa-T

Thanks!  :Smilie:

----------

