After setting 'layers to the layers object, I stupidly assumed that (vla-item layers <name>) would return nil if the <name> layer didn't exist.
WRONG, you get the Automation error.
Simple fix...
(setq name "whatever")
(and
(tblsearch "layer" name)
(setq layobj (vla-item layers name))
;; continue
)
because (tblsearch) will return nil if the named layer does not exist, and will cease further evaluation within the (and ...).
Yes, you could use the catch-all approach instead.