Skip to main content

Using the Excel COM server - Fill a column in msexcel with color Gray.

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

A macro was created in msexcel to fill column "J" with color Gray.  Editing the macro shows the following VB code.

Sub Macro1()

Columns ("J:J").Select

With Selection.Interior

       .ColorIndex = 15

       .Pattern = xlSolid

End With

End Sub

Question: What's wrong with this code?

invoke  ExcelObject  "getColumns"    using  z"J"

                                                      returning CellRange.

invoke CellRange     "setColorIndex" using by value 15.

invoke CellRange     "finalize"           returning CellRange.

Also tried "getRange" using z"J:J: then "select", but did not work.

How should this be coded in COBOL?

Resolution:

Notes: In order to use the setColorIndex property in Excel one addition object must be used.

In the following example the color of the  interior of the cellls within the selected range of cells will be changed to 15 which is gray

invoke ExcelObject "getRange" using z"A1:C1"                

                               returning CellRange           

invoke CellRange "Select"                                   

invoke CellRange "getInterior" returning Interior            

                                                            

invoke Interior "setColorIndex" using by value 15            

                       

Old KB# 4444