This is read an Excel example it just reads an open spreadsheet, and shows the result of a read cells. You could make a list of the cells.
For your task you will probably need to use OBDX as you may have different dwg names, OBDX will allow you to change multiple dwgs.
; https://www.cadtutor.net/forum/topic/98627-block-definition-modification-adding-2-attributes/
; Excel link by AlanH Aug 2025
(defun wow ( / myxl)
; thanks to Lee-mac for this defun
; 58 is Colon
; thanks to Lee-mac for this defun
; www.lee-mac.com
; 44 is comma 9 is tab 34 is space 58 is colon
(defun csv->lst58 ( str / pos )
(if (setq pos (vl-string-position 58 str))
(cons (substr str 1 pos) (csv->lst58 (substr str (+ pos 2))))
(list str)
)
)
; get range
(defun AH:getrangexl ( / lst1 myrange lst1)
(setq lst1 '())
(setq myrange (vlax-get-property (vlax-get-property (vlax-get-property myxl "ActiveSheet") 'UsedRange) 'address))
(setq lst1 (csv->lst58 myrange))
(setq st (vl-string-subst "" "$" (vl-string-subst "" "$" (nth 0 lst1) )))
(setq end (vl-string-subst "" "$" (vl-string-subst "" "$" (nth 1 lst1) )))
(setq row1 (cadr (columnrow st)))
(setq endrow (cadr (columnrow end)))
(setq endcol (car (columnrow end)))
)
; Alpha2Number - Converts Alpha string into Number
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
; Str$ = String to convert
; Syntax example: (Alpha2Number "ABC") = 731
;-------------------------------------------------------------------------------
(defun Alpha2Number (Str$ / Num#)
(if (= 0 (setq Num# (strlen Str$)))
0
(+ (* (- (ascii (strcase (substr Str$ 1 1))) 64) (expt 26 (1- Num#)))
(Alpha2Number (substr Str$ 2))
)
)
)
; ColumnRow - Returns a list of the Column and Row number
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
; Cell$ = Cell ID
; Syntax example: (ColumnRow "ABC987") = '(731 987)
;default to "A1" if there's a problem
;-------------------------------------------------------------------------------
(defun ColumnRow (Cell$ / Column$ Char$ Row#)
(setq Column$ "")
(while (< 64 (ascii (setq Char$ (strcase (substr Cell$ 1 1)))) 91)
(setq Column$ (strcat Column$ Char$)
Cell$ (substr Cell$ 2)
)
)
(if (and (/= Column$ "") (numberp (setq Row# (read Cell$))))
(list (Alpha2Number Column$) Row#)
'(1 1)
)
)
;; Thanks to fixo
(defun getcell2 (row column / )
(setq cells (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Cells"))
(setq cell (vlax-get (vlax-variant-value (vlax-get-property cells "Item" row column)) 'value))
)
(defun openxl ( / )
(setq myxl (vl-catch-all-apply 'vlax-get-or-create-object '("Excel.Application")))
(if (vl-catch-all-error-p myxl)
(progn
(prompt "\nError: Could not start Excel.")
(exit)
)
)
(if (= (vlax-get-property (vlax-get-property myXL 'WorkBooks) 'count) 0)
(vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add)
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
(princ)
)
; starts here
(openxl)
(AH:getrangexl)
; ignore 1st line
(setq row (+ row1 1))
(repeat (- endrow 1)
(setq dwgname (getcell2 row 1))
(setq bhd_inst (getcell2 row 2))
(setq bhd_line (getcell2 row 3))
(setq bhd_type (getcell2 row 4))
(princ (strcat"\n" dwgname " " bhd_inst " " bhd_line " " bhd_type))
(setq row (1+ row))
;***********************************
; do your thing here
;***********************************
)
(if (not (vlax-object-released-p myXL))(progn(vlax-release-object myXL)(setq myXL nil)))
(princ)
)
(wow)