Reputation: 49
I have an application that creates an ExcelWorkbook. In workbook have some sheets and i want to change color of the tab color for each sheets. Example Code Below:
ExcelApplication.WorkBooks[1].WorkSheets[1].Name := 'Sheet1';
ExcelApplication.WorkBooks[1].WorkSheets[1].Name.ColorIndex := 3; // Raise in here
Is there any suggestion?
Upvotes: 0
Views: 916
Reputation: 30735
I think you're trying to set a property which doesn't exist, i.e. the Name property of a WorkSheet's tab doesn't have a ColorIndex (or Color) sub-property.
The following code sets the tab's color to red for me:
WorkBook.WorkSheets[1].Select;
WorkBook.WorkSheets[1].Tab.Color := 255;
WorkBook.WorkSheets[1].Tab.TintAndShade := 0;
Btw, code completion in the Delphi IDE should work if your unit Uses the interface unit for Excel and you are doing "early binding" against Excel objects. The one for Excel2000 which came with D7 is called Excel2000.Pas. However, a strange thing about it is that the WorkSheet interface definition in there does not include a Tab property. I don't know why. However, if you go into the Visual Basic part of Excel (via the Developer tab on the "ribbon" in Excel2007 and later), there is OLH for the Excel objects and this does include the WorkSheet Tab property. That means that you can access it, but using "late binding", i.e. using Variants, rather than early binding.
Upvotes: 4