Results 1 to 5 of 5

Thread: the color of an Excell cell

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Belgium
    Posts
    98

    Post

    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

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    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.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Belgium
    Posts
    98

    Post

    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


  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    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.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Belgium
    Posts
    98

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width