Consulting

Results 1 to 3 of 3

Thread: Inserting Table into word from Excel VBA

  1. #1
    VBAX Newbie
    Joined
    Apr 2007
    Posts
    2
    Location

    Inserting Table into word from Excel VBA

    Hi,

    How would i do this i've tried this but it displays a 'Wrong Number of arguments error'

    Code:
    .ActiveDocument.Tables.Add NumRows:=2, NumColumns:= _ 2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _ wdAutoFitFixed


    Thanks

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi jonn,
    You might try looking in word vba on how to create your table and then try it from excel. An example from the word help file:
    [VBA]Selection.Collapse Direction:=wdCollapseStart
    Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=5, NumColumns:=5)
    myTable.AutoFormat Format:=wdTableFormatClassic2[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    This is a simple syntax error. Look closely.

    .ActiveDocument.Tables.Add NumRows:=2, NumColumns:= _ 2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _ wdAutoFitFixed

    [vba].ActiveDocument.Tables.Add NumRows:=2, NumColumns:=2, _
    DefaultTableBehavior:=wdWord9TableBehavior, _
    AutoFitBehavior:=wdAutoFitFixed[/vba]Your underscore characters are in the wrong place. The one before wdAutoFitFixed should not be there at all.

Posting Permissions

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