Programmatically lock and put bakcolor as yellow only to the head



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


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.


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



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