I am trying to fill a cell in Excel (2003) on Windows with the colour black. I get the following error;
Exception code 0: Unable to set the ColorIndex property of the Interior class, (failed on “ColorIndex”)
The line I am using is this
I would ideally like to fill the cell with a diagonal pattern but the VBA doesn’t seem to translate very well. Any suggestions appreciated;
VBA code below;
// With Selection.Interior
// .ColorIndex = 0
// .Pattern = xlUp
// .PatternColorIndex = xlAutomatic
// End With
// End Sub
You are right, some VBA translates well and some code does not. Here is a working example with some code from my book which may help:
[code] Dim excel as new ExcelApplication
excel.Visible = True
excel.Range(“A1”).Interior.Pattern = Office.xlSolid
excel.Range(“A1”).Interior.ColorIndex = 1
excel = nil
exception err as OLEException
The pattern for translating the rest of the code can be seen. Here is a link to the bookstore with other helpful articles and books on Xojo.
Happy to help
Thanks Eugene I have all your books but could not quite get it right late last night.
Is the above code working on the computer, or would you like a hand with some troubleshooting?
Let me know if this works for you.
No its working fine, I think it may have been a problem with the worksheet being protected - even though the cells I was changing were editable areas. I have unprotected the sheet and it works fine now.