Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA to add column below, upon button press. (Word 2000 (sp3))

    Hello,
    I am trying to create a Word

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 30 Times in 30 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    Welcome to Woody's Lounge!

    The attached document shows a possible approach. There is a macrobutton field below the table that calls the AddRow macro. This macro duplicates the last row of the table.

    (This example is based on the thread starting at <post:=651,740>post 651,740</post:> where the user wanted the last row to be duplicated automatically).

  3. #3
    New Lounger
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    thanks for reply, however it errors...

    Compile error:
    Method or data member not found

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 30 Times in 30 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    Sorry about that, I see that the PasteAppendTable method was introduced in Word 2002. Try changing the line

    Selection.PasteAppendTable

    in the code to

    Selection.Paste

  5. #5
    New Lounger
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    Many Thanks, I am now using this code

    Sub AddRow()
    Selection.MoveUp
    ActiveDocument.Unprotect
    Selection.SelectRow
    Selection.Copy
    Selection.MoveDown Unit:=wdLine
    Selection.Paste
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End Sub

    Two future questions if I may.
    1- Can the code be amended, so it only copies the format, and not the content of the copied row. So it's a new blank line ready for Users to enter information?
    2- My plan is to have several Tables, with a 'button' underneath each one. If reproduced, will this code target the right tables, i.e. the one directly above the 'button' ?

    Many Thanks again, this is much appreciated.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 30 Times in 30 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    I'll have to look into 1.
    2 - Yes, you can place a macrobutton field directly below each table and let it execute the same AddRow macro. The code moves up one line from the macro button and copies the row it finds there.

    Added later Oops, I'm wrong, the code works on whatever was the selection before you clicked the macrobutton. I'll have to rethink this.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 30 Times in 30 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    It turned out to require slightly different code, with a separate macro for each table. Try the attached version.

  8. #8
    New Lounger
    Join Date
    Jul 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to add column below, upon button press. (Word 2000 (sp3))

    That works a treat

    MANY thanks for your time and effort!

    GriZlore

Posting Permissions

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