PDA

Click to See Complete Forum and Search --> : the color of an Excell cell


R@emdonck
Dec 13th, 1999, 06:30 AM
Hi,

How do I change the back color of an Excell cell and the color of the text in an Excell cell?

R@emdonck

MyCode:

Public Sub stored_procedure_b2()
Const xlExcel5 = 39
Dim XLS As Object ' for the application
Dim XLSheet As Object ' for the worksheet
Set XLS = CreateObject("Excel.Application")


' To Open an existing workbook

XLS.Workbooks.Open ("C:\Shiftverslag\B2 Usage Report1.xls")


' Open the Worksheet named "Input"

Set XLSheet = XLS.Worksheets("Input")

' Set Column Names

XLSheet.Cells(6, 2) = (str_date + (6 / 24)) 'date


'Open the Worksheet named "plan"
Set XLSheet = XLS.Worksheets("plan")

'set new colors

???????????????????????????



'print
XLSheet.PrintOut

' Don't save
XLSheet.Parent.Saved = True
' DO NOT forget to quit the excel app and also to release the objects...
XLSheet.Application.Quit
' Release the Excel object variables
Set XLSheet = Nothing
Set XLS = Nothing
End Sub

QWERTY
Dec 13th, 1999, 06:52 AM
To change the color of one cell:
Selection.Interior.ColorIndex = 3. It will change background of selected cell to red.
To change font color:
Selection.Font.ColorIndex = 5. It will change text color to blue.

If you have any problems with Excel what you can do is to record the macro (Tools~~>Macro~~>Record New Macro) and then just use the code the computer generated (use VBA to do that)
Hope this helps

------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.

R@emdonck
Dec 13th, 1999, 07:17 AM
Hi,

I know about the recording of macro's in Excell, but that didn't help me in this case.
Also the
"Selection.Interior.ColorIndex = 3. It will change background of selected cell to red.
To change font color:
Selection.Font.ColorIndex = 5. It will change text color to blue."

didn't work.

Sorry, R@emdonck

QWERTY
Dec 13th, 1999, 08:24 AM
To make it work you have to select cell first. Example:
Cells(1,1).Select
Selection.Interior.ColorIndex = 3

Same with Fonts. If it still doesn't work, well I don't know what it is because it works on my PC (Win 98, Office 97)

------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.

R@emdonck
Dec 13th, 1999, 08:46 AM
I can't get it to work!!

Here is the code I use. Can you make it work?

Public Sub stored_procedure_b2()
Const xlExcel5 = 39
Dim XLS As Object ' for the application
Dim XLSheet As Object ' for the worksheet
Set XLS = CreateObject("Excel.Application")


' To Open an existing workbook

XLS.Workbooks.Open ("C:\Shiftverslag\B2 Usage Report1.xls")


' Open the Worksheet named "Input"

Set XLSheet = XLS.Worksheets("Input")

' Set Column Names

'XLSheet.cells(6, 2) = (str_date + (6 / 24)) 'datum
'XLSheet.cells(6, 4) = str_shift


'Open the Worksheet named "Verslag"
Set XLSheet = XLS.Worksheets("plan")

'this is where it goes wrong

XLSheet.cells(6, 10).select
XLSheet.selection.interior.colorindex = 15


'print
XLSheet.PrintOut

' Don't save
XLSheet.Parent.Saved = True
' DO NOT forget to quit the excel app and also to release the objects...
XLSheet.Application.Quit
' Release the Excel object variables
Set XLSheet = Nothing
Set XLS = Nothing
End Sub


R@emdonck