- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have looked for this everywhere but I couldn't find it. So I'm posting here. As a part of a Lisp routine I'm trying to create a sub function which opens an excel file and selects a range in it. And then I want it loop through each cell in the range and check for it's interior color. If the color of a particular cell is "15849925", I want to change it to "16777215".
I was able to do this in vba using "For each cell in Range" statement. But I want to do this using VLISP. Here is what I got so far.
;;-------------------------------------------------------------------------------;;
;To set the color of a cell to 16777215 in a range, if the interior color of the cell is 15849925
(defun c:xc ()
(setq xlApp (vlax-get-or-create-object "excel.application"))
(setq xlWb (vlax-get-property xlApp "workbooks"))
(vlax-invoke-method xlWb "open" "D:\\example.xlsx")
(setq xlSheet (vlax-get-property xlApp "activesheet"))
(setq xlRange (vlax-get-property xlSheet "Range" "A9:J30"))
(;I want to do somethin here like the following
(foreach xlcell (xlRange)
(if (= (vlax-get-property xlCell "color") "15849925")
(vlax-put-property xlCell "color" "16777215")
) ;end for each
;I know it's wrong. I don't know how to loop through each cells in the range.
)
(vlax-release-object xlRange)
(vlax-release-object xlSheet)
(vlax-invoke-method (vlax-get-property xlApp "Activeworkbook") 'Close :vlax-True)
(vlax-release-object xlWb)
(vlax-release-object xlApp)
);end defun
Thanks in advance.
Silambarasan A
Solved! Go to Solution.