+ Reply to Thread
Results 1 to 3 of 3

Fit a table (rows) from excel in Word using VBA

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Texas
    MS-Off Ver
    Window 7
    Posts
    0

    Fit a table (rows) from excel in Word using VBA

    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...
    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

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello Isa-T,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    08-07-2014
    Location
    Texas
    MS-Off Ver
    Window 7
    Posts
    0

    Re: Fit a table (rows) from excel in Word using VBA

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to Import Column/Rows from Word Table to Excel Columns
    By atom2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2014, 01:57 AM
  2. Convert Word to Excel based upon Word Table of Contents
    By jcappuccino7 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-06-2013, 01:25 PM
  3. VBA to copy X rows of data from Excel to Word table
    By gn1664 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2012, 03:01 PM
  4. Macro that finds word in table and reports all rows with data to new table
    By jermsalerms in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2007, 03:57 AM
  5. Heading rows repeat in word embedded excel table
    By Turnipboy in forum Excel General
    Replies: 0
    Last Post: 06-23-2005, 04:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1