There are cases when you want to implement conditional formatting in an Excel file. For example, you would like to highlight all the values that are less than "0" in red for a particular column.
In this article, you will learn how to apply conditional formatting while using the Execute macro activity in Studio Pro.
Here’s how to do it in a few steps:
- Follow the instructions provided in the Execute Macro article.
- Copy and paste the VBScript below that shows how to highlight all the values less than 0 in red for the range A1:A40.
Dim rng, fc, xlApp, EmailBook
Set xlApp = CreateObject("Excel.Application")
Set Book = xlApp.Workbooks.Open(WScript.Arguments(0))
Set Sheet = Book.Sheets("data")
Set rng = Sheet.Range("A1:A40")
Set fc = rng.FormatConditions.Add(1, 6, 0)
.Color = RGB(255, 0, 0)
fc.StopIfTrue = False
Note: The above VBScript can be modified to include another conditional formatting as well.