Micro Focus QTP (UFT) Forums
Highlighting the cell in Excel! - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Highlighting the cell in Excel! (/Thread-Highlighting-the-cell-in-Excel)



Highlighting the cell in Excel! - nageshpv - 08-18-2008

Hi,
I need to check the value in the Cell of the excel sheet and have to highlight it with some color.
For example: If the cell has FALSE as the value, i need to highlight the text with Red color.

Can anyone please help me out.

thanks


RE: Highlighting the cell in Excel! - Rekha - 08-19-2008

Hi Nagesh PV,

You can have an idea of changing cell interior/ font colors in excell sheet from the following code.

Code:
Set  xl=createobject ("excel.application")
set xls=xl.workbooks.add
For i=0 to 54
    xls.sheets(3).cells(i,1)=i
    xls.sheets(3).cells(i,1).interior.colorindex=i
      xls.sheets(3).cells(i,1).Font.colorindex=i+20
Next

xls.saveas""C:\Documents and Settings\rekha\Desktop\Colors.xls""
xls.quit
xl.quit
xls=nothing
xl=nothing



Try this and let us know how it worked for you.
Rekha


RE: Highlighting the cell in Excel! - nageshpv - 08-19-2008

Hi Rekha,

I could manage with the code..thanks a lot!


RE: Highlighting the cell in Excel! - nageshpv - 08-19-2008

I tried with the code below,
Code:
Public Function Highlight_Cell()
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set ObjWorkBook = objExcel.Workbooks.open (DataSheet_Path &"\" &  "DWU.xls")
   Set ObjWorkSheet = ObjWorkbook.WorkSheets("DS_Result")
    For Each Cell In ObjWorkSheet.UsedRange
    If Cell.Value = "False" Then
      Cell.Interior.ColorIndex = 3
     End If
  Next
ObjWorkBook.Save
ObjWorkBook.close
Set objExcel = nothing
End Function

It works fine for me.