Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Ohio, USA
    Posts
    163
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form to Word Tables (Excell 2000/SR-1 & VBA)

    I'm using an Excel form to gather data that is then being passed to a complete Word Document. All of my form is working correctly except for two data hand-offs.

    When going to Word, I'm using Tables and code like this:
    WordDoc.Tables.Item(1).Rows.Item(7).Cells.Item(2). Select
    WordAp.Selection.Text = txtPurchStreet.Text

    Where I have to know the item/row/cell I'm pasting to.
    For this particular problem, I'm in a new section, so I'm assuming it's a new item. I keep getting an error.

    I searched the archives on this but probably don't know what to search for. Is there a way to tell what object (item) / Row/ Cell you are pasting to without trial and error? In other words, when I look at my Word form, is there a simple way to lable all the cells, etc on my form? Or to see that info?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Form to Word Tables (Excell 2000/SR-1 & VBA)

    I think Table.Items(1) is the first table in the collection for whatever object it follows. Thus, if the object is the entire document, rather than a section, you would need to use the next table in the document. On the other hand, you could address each section individually:

    <pre>Sub TableCountsBySection()
    Dim intCounter As Integer
    With ActiveDocument
    For intCounter = 1 To .Sections.Count
    Debug.Print "Section " & intCounter & " contains " & _
    .Sections(intCounter).Range.Tables.Count & " table(s)."
    Next
    End With
    End Sub</pre>

    You can retrieve a variety of properties of the table using the .Information(wdConstant) construction, including the total number of rows and columns. For example:

    ActiveDocument.Tables(1).Range.Information(wdMaxim umNumberOfRows)
    ActiveDocument.Tables(1).Range.Information(wdMaxim umNumberOfColumns)

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Form to Word Tables (Excell 2000/SR-1 & VBA)

    Just to tack on a couple of bits to Jefferson's advice:

    You don't need to use "Item" in this situation; for example instead of
    <pre>WordDoc.Tables.Item(1).Rows.Item(7).Cells.Ite m(2)</pre>

    use:
    <pre>WordDoc.Tables(1).Rows(7).Cells(2)</pre>

    The only common use for .Item that I can think of is when using a 'With' construct along the lines of:
    <pre>With ActiveDocument.Bookmarks
    .Item("bmk1").Range.Text = strText1
    .Item("bmk2").Range.Text = strText2
    End With
    </pre>

    Also, you don't need to select the cell to write text to it; you can simply use:

    <pre>WordDoc.Tables(1).Rows(7).Cells(2).Range.Te xt = txtPurchStreet.Text
    </pre>

    Gary

Posting Permissions

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