If Statement for cursor location in document

  • Thread starter Thread starter Owen
  • Start date Start date
O

Owen

Hi

I am looking to write a macro that tests the cursor position within a
document. Where the IF statement is true, then i would like to be able to
delete the current row in a table.
Where the IF statement is false, then i would like nothing further to occur.
I am basically giving the user the ability to delete a row within a form,
but want to protect specific rows from deletion.

I have attempted the code below, however there is a problem with the first
line
If ActiveDocument.Tables(12).Rows(2) Then
ActiveDocument.Protect (wdAllowOnlyFormFields), Password:="ngo999",
NoReset:=True
Else
Selection.SelectRow
Selection.Rows.Delete
ActiveDocument.Protect (wdAllowOnlyFormFields), Password:="ngo999",
NoReset:=True

Any help would be greatly appreciated.
 
Use

Dim row2 As Row
With ActiveDocument.Tables(12)
If .Rows.Count > 1 Then
Set row2 = .Rows(2)
If Selection.Range.InRange(row2.Range) Then
row2.Delete
End If
End If
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Back
Top