PDA

View Full Version : Solved: Error when trying to delete row by macro



clhare
03-19-2013, 07:22 AM
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:
'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

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

macropod
03-19-2013, 09:49 PM
The following works for me in both Word 2003 & 2010:
Sub DeleteRowAtCursorPosition()
With Selection
If .Information(wdWithInTable) Then .Rows.Delete
End With
End Sub
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.

clhare
03-20-2013, 05:19 AM
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