Macro Problem

O

Owen

I am using the following Macro in a protected form.

The intention of the macro is to determine if the cursor is within any of
Tables 4 to 8, and if the result is true then copy the current row from that
table and insert it in the row below.

For some reason, although the macro runs without errors, the new row is not
created even when i know my selection is within Tables 4 to 8.

Would be great if someone can spot the problem in my code.

Sub AddRevisionTableRow()
ActiveDocument.Unprotect
Dim oTbl As Table
For x = 4 To 8
With ActiveDocument
Set oTbl = .Tables(x)
If Selection.Range.InRange(oTbl.Range) Then
Selection.SelectRow
Selection.Copy
Selection.Collapse
Selection.MoveDown unit:=wdLine, Count:=1
Selection.Paste
Else
End If
End With
Next x
ActiveDocument.Protect (wdAllowOnlyFormFields), NoReset:=True
End Sub
 
G

Graham Mayor

It works for me. Add a messagebox to ensure you really are in the required
table - as below.

Sub AddRevisionTableRow()
ActiveDocument.Unprotect
Dim oTbl As Table
For x = 4 To 8
With ActiveDocument
Set oTbl = .Tables(x)
If Selection.Range.InRange(oTbl.Range) Then
MsgBox "In table " & x
Selection.SelectRow
Selection.Copy
Selection.Collapse
Selection.MoveDown unit:=wdLine, Count:=1
Selection.Paste
End If
End With
Next x
ActiveDocument.Protect (wdAllowOnlyFormFields), NoReset:=True
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
O

Owen

Graham

Thanks for the response. I have just realised my problem...i had assigned
the wrong macro to my menu. You helped me confirm i wasn't completely losing
it though!
 

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