Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Upstate, South Carolina, USA
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replicating Table with Control Button Code (VBA/Wo

    I have created a table that enables the user to click on a command button, select a picture, and the VBA code resizes the file to fit the table cell. The table allows the user to insert six (6) pictures. The VBA code for the command buttons points to a common procedure.

    What I want the user to be able to do is insert a new page, copy and paste the table on the new page and have the command button code also replicated.

    Is there a way to accomplish this with Cut-and-Paste operations? Or do I have to rebuild the table each time the user wants a new page of pictures (ugh!)?

    Thanks,
    Al
    "Do or do not do. There is no try." -- Yoda
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>

  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: Replicating Table with Control Button Code (VB

    Copying and pasting a table is no problem, but copying a control and pasting it may disconnect it from your code. Have you tried it manually to see whether the CommandButton will still work?

    To copy the table, you can use either the Selection object (if the insertion point is in the table) or the document's Tables collection. Common methods for identifying a table are:

    Selection.Tables(1) ' first table in selection
    ActiveDocument.Content.Tables(ActiveDocument.Conte nt.Tables.Count) ' last table in body

    (Note: I typed that in, not testing for any spelling error or objects/properties missing in the chain.)

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Upstate, South Carolina, USA
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replicating Table with Control Button Code (VB

    Many thanks for your reply.

    >> Have you tried it manually to see whether the CommandButton will still work?
    No, the CommandButton doesn't work because when Word performs the paste operation, it assigns new numbers to the pasted CommandButtons and doesn't replicate the CommandButton VBA code. So,

    Private Sub CommandButton11_Click()
    <Procedure>
    End Sub

    when pasted becomes

    Private Sub CommandButton21_Click()

    End Sub

    If someone could recommend an elegant procedure that would replicate the table, CommandButtons, and CommandButton code, that'd be great. Otherwise, I'll just create a Word template with enough tables for the specific purpose.

    Thanks,
    Al
    "Do or do not do. There is no try." -- Yoda
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replicating Table with Control Button Code (VB

    Do you really need a seperate Commandbutton for each tablecell? If not, you can create a single commandbarbutton (on a standard or custom commandbar) that checks if the cursor is within a table and if so, inserts a picture at the cursor position:

    <font face="Georgia">If Selection.Information(wdWithinTable) Then
    ' your code to insert a picture
    End If</font face=georgia>

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Upstate, South Carolina, USA
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replicating Table with Control Button Code (VB

    What a great idea! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    Thanks for thinking outside my box. I'll do it.
    Al
    "Do or do not do. There is no try." -- Yoda
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>

  6. #6
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Upstate, South Carolina, USA
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replicating Table with Control Button Code (VB

    Jan,

    This worked so well that I also incorporated automatic generation of the desired table with the cursor left in cell 1.

    Thanks again,
    Al
    "Do or do not do. There is no try." -- Yoda
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replicating Table with Control Button Code (VB

    You're welcome!
    Glad it works for you.

Posting Permissions

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