Jean-Guy Marcil said:
Bonjour,
Dans son message, < Alex > écrivait :
I don't have my 2003 version installed at the moment, so I cannot
look up the new VBA objects related to that new feature.
I bet that if you used the macro recorder to protect a cell, and then
look at the code, that would be a great place to start.
Also, since you want to do this programmatically, you should post in
the vba.general or vba.beginners groups (Choose one, not in both!).
By the way, next time you post a question, I think it would be a good
idea to try to explain in a few more details what you want to do.
Here is your original post:
<quote>
how to make a cell readonly
<unquote>
You have to admit that it was not really clear that you wanted to do
this programmatically, or that you already knew how to do that
manually, or that you had Word 2003... Especially since the message
was identical to the subject line..
The way the new protection feature is set up, you don't directly protect a
specific cell or other range. Instead, you assign "editors" who are allowed
to modify certain areas, and any area that doesn't have any editor will be
protected. Although you can specify individual people as editors by
supplying their email addresses, you probably want the Everyone group to be
able to edit the parts outside the protected cell.
As far as I can tell, it isn't possible to assign Everyone as the editor for
the whole document and then delete that editor for the specific cell to be
protected. You must assign the editor for each individual range that is not
the protected cell: the area before the table, the area after the table, all
rows in the table before the cell, all rows after the cell, and the cells in
the same row to the left and right of the protected cell.
The following macro is extremely simplified, as noted in the comment...
Sub ProtectCellOnly()
' Oversimplified example:
' Assume the document has one table, and you
' want to protect the cell in the second row,
' second column.
' Note: in a real environment you need error-
' checking to ensure there is a table and that
' it has a .Cell(2,2). The macro will also fail
' if the table contains any split cells or
' nested tables.
Dim oRg As Range
Dim oTbl As Table
Dim oRow As Row
Dim oCell As Cell
Set oTbl = ActiveDocument.Tables(1)
Set oRg = ActiveDocument.Range
oRg.End = oTbl.Range.Start ' = doc range before table
oRg.Editors.Add wdEditorEveryone
Set oRg = ActiveDocument.Range
oRg.Start = oTbl.Range.End ' = doc range after table
oRg.Editors.Add wdEditorEveryone
For Each oRow In oTbl.Rows
If oRow.Index <> 2 Then
oRow.Range.Editors.Add wdEditorEveryone
Else
For Each oCell In oRow.Cells
If oCell.Column.Index <> 2 Then
oCell.Range.Editors.Add wdEditorEveryone
End If
Next oCell
End If
Next oRow
ActiveDocument.Protect Type:=wdAllowOnlyReading
End Sub