Consulting

Results 1 to 3 of 3

Thread: Solved: Error when trying to delete row by macro

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Solved: Error when trying to delete row by macro

    I have a template from Word 2003 that I am testing in Word 2010. I am getting an error (wrong number of arguments or invalid property assignment) when I run the macro that is supposed to delete a table row.

    The code (from 2003) is as follows:
    [vba]'Callback for g4b13 onAction
    Sub DeleteRowAtCursorPosition()

    ' Select the row and delete it
    Selection.SelectRow
    Selection.Rows.Delete
    ' Collapse selection to an insertion point
    Selection.Collapse Direction:=wdCollapseStart
    End Sub[/vba]

    I tried re-recording the steps and get the same code, so I don't know why it won't work in my macro.

    Cheryl

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The following works for me in both Word 2003 & 2010:
    [vba]Sub DeleteRowAtCursorPosition()
    With Selection
    If .Information(wdWithInTable) Then .Rows.Delete
    End With
    End Sub[/vba]
    PS: You'd do better to post this kind of question in the Word forum, as it really has nothing to do with the Ribbon.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    I have this macro on a button on the ribbon, which is why my mind went to this forum instead.

    I did try your macro instead of mine, and I got the same error. As I looked at the code again, I realized what was wrong...I did not have "control As IRibbonControl" in parentheses in the sub name. Once I added that, the button worked correctly.

    I double-checked my template and that's the only instance where I missed that.

    Cheryl

Posting Permissions

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