If Statement for cursor location in document

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.
 
D

Doug Robbins - Word MVP on news.microsoft.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top