That did in deed work, but I also want to skip all rows and cells that have a style type of Title or Header. I can do it if the entire row is set as a title or header, using the code below, but I have been trying to mess around with vla-getcellstyle and haven't yet figured out how to integrate that into this code, as I am still not great with the lambda functions. I could rewrite the whole thing to not use lambda, but that would slow it down a bit, so hopefully someone has a simpler way.
;; Alternating Table Background Colour - Lee Mac
;; Modified by Chris Wade 07/11/2018 to ignore Title and Header rows
(defun c:altback ( / *error* acc col fnc idx obj row sel tmp RowType CellStyle1)
(defun *error* ( msg )
(if (and (= 'vla-object (type acc)) (not (vlax-object-released-p acc)))
(vlax-release-object acc)
)
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(setq col '(215 215 215)) ;; True Colour (r g b) for cell background
(if (setq sel (ssget "_:L" '((0 . "ACAD_TABLE"))))
(if (setq acc (vla-getinterfaceobject (vlax-get-acad-object) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
(progn
(apply 'vla-setrgb (cons acc col))
(repeat (setq idx (sslength sel))
(setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))
col (vla-get-columns obj)
)
(vla-put-regeneratetablesuppressed obj :vlax-true)
(repeat (setq row (vla-get-rows obj))
(setq RowType (vla-getrowtype obj row))
(if (and (zerop (rem (setq row (1- row)) 2)) (/= RowType acHeaderRow) (/= RowType acTitleRow))
(setq fnc (lambda ( a b ) (vla-setcellbackgroundcolor obj a b acc)))
(setq fnc (lambda ( a b ) (vla-setcellbackgroundcolornone obj a b :vlax-true)))
)
(repeat (setq tmp col) (fnc row (setq tmp (1- tmp))))
)
(vla-put-regeneratetablesuppressed obj :vlax-false)
)
(vlax-release-object acc)
)
(princ "\nUnable to interface with AcCmColor object.")
)
)
(princ)
)
(vl-load-com) (princ)