Programmatically lock and put bakcolor as yellow only to the head

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

Hi,
I am exporting records from access to an excel sheet. The following is a
part of my code:
Set xlc = xls.Range("A1") ' this is the first cell into which data go


Set dbs = CurrentDb()


Set rst = dbs.OpenRecordset("ExcelExp", dbOpenDynaset, dbReadOnly)

If rst.EOF = False And rst.BOF = False Then

rst.MoveFirst

If blnHeaderRow = True Then
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).Value = rst.Fields(lngColumn).Name
xlc.Offset(0, lngColumn).Locked
Next lngColumn
Set xlc = xlc.Offset(1, 0)
End If
However the code to lock each of the header cell is not working. I would
appreciate any help for resolution of the above issue. Also how does one make
the backcolor yellow for each of the header cell in the above process.
Thanks.
 
Locking the cells only takes effect when you Protect the worksheet (under
the tools menu)
In Code something like :
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

Setting background colors goes something like
.ColorIndex = 44
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic

Regards

Kevin
 
Back
Top