change Excel Cell Forecolor using VB6


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: change Excel Cell Forecolor using VB6

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    319

    change Excel Cell Forecolor using VB6

    Hi All
    Greetings. The version that I have writtin using LISTVIEW is working very well. I have another interesting problem which is beyong my knowledge. I have been asked to display in the Excel Cell forecolor in RED and not the backcolor if the exported data from ACCESS Sales Table whose sales value did not meet certain value.

    this script is not working:
    objWorksheet.Cells(intRow, intCol).Fill.Schemecolor = vbRed

    Here is part of the overall VB6 script that I have written
    Do Until .EOF
    intCol = 0
    intRow = intRow + 1
    For i = 0 To (.Fields.Count - 1) Step 1
    intCol = intCol + 1

    objWorksheet.Cells(intRow, intCol) = .Fields(i).Value

    If .Fields("SalesAmt").Value < 500 Then
    objWorksheet.Cells(intRow, intCol).Fill.Schemecolor = VbRed
    End If

    .MoveNext
    Loop
    Cheers,
    Lennie

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Excel's macro recorder is your friend. Begin recording a macro, then manually perform the action(s) you wish to automate -- in this case, changing the forecolor of a cell -- then look at the code that was recorded. Try this:

    objWorksheet.Cells(intRow, intCol).Font.Color = vbRed
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Replies: 7
    Last Post: 02-22-2008, 10:42 AM
  2. vb6 error opening excel
    By Nick313 in forum VB Classic
    Replies: 2
    Last Post: 11-15-2007, 04:16 PM
  3. Detect Excel Version in VB6 Application
    By Ifgash in forum VB Classic
    Replies: 1
    Last Post: 04-23-2006, 03:58 AM
  4. Dynamic cell border color change
    By Scott in forum Web
    Replies: 2
    Last Post: 01-08-2002, 04:54 AM
  5. I'll change from VB6 to C#, and why
    By Phil in Austin in forum .NET
    Replies: 15
    Last Post: 02-08-2001, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center