V
VBA Neophyte
I have a macro creating a document with a table containing multiple header
rows. I want to sort on the other rows. To exclude the header rows, I define
and then select a range containing these other rows. But when I try to sort
the selection I get a message that the document is protected (which it's
not). Here's the error:
"Run-time error 4605: This method or property is not available because the
document is a protected document."
See code below. The Selection.Sort statement is the highlighted error.
Any idea why? Or, is there a better way to sort a range in a table? (I've
tried just sorting with a range, same result.)
Here's the code:
With ActiveDocument
Set sortRange = Range(Start:=.Tables(1).Rows(7).Range.Start, _
End:=.Tables(1).Rows.Last.Range.End)
sortRange.Select
Selection.Sort ExcludeHeader:=False, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldAlphaNumeric, _
SortOrder:=wd SortOrderDescending, _
FieldNumber2:="Column 1", _
SortFieldType2:=wdSortFieldNumeric, _
SortOrder2:=wd SortOrderAscending
End With
rows. I want to sort on the other rows. To exclude the header rows, I define
and then select a range containing these other rows. But when I try to sort
the selection I get a message that the document is protected (which it's
not). Here's the error:
"Run-time error 4605: This method or property is not available because the
document is a protected document."
See code below. The Selection.Sort statement is the highlighted error.
Any idea why? Or, is there a better way to sort a range in a table? (I've
tried just sorting with a range, same result.)
Here's the code:
With ActiveDocument
Set sortRange = Range(Start:=.Tables(1).Rows(7).Range.Start, _
End:=.Tables(1).Rows.Last.Range.End)
sortRange.Select
Selection.Sort ExcludeHeader:=False, FieldNumber:="Column 2", _
SortFieldType:=wdSortFieldAlphaNumeric, _
SortOrder:=wd SortOrderDescending, _
FieldNumber2:="Column 1", _
SortFieldType2:=wdSortFieldNumeric, _
SortOrder2:=wd SortOrderAscending
End With