How to open an excel file using Lisp

Hi, the company I work for has recently converted from AutoCAD to BricsCAD (on my recommendation), they use a number of Lisp routines to make life a bit easier, while the majority work perfect, albeit with a little tweek here and there, one however is refusing to cooperate.
the operation is as follows, click a command button on the ribbon and excel opens a recently created data sheet, the issue being excel opens but to the front screen not the file, is this due to BricsCAD using .CSV rather than .XLS?
I should point out that all these codes were written by someone else 8 years ago and any alterations I have made have been using done the knowledge of other users on forums such as this one (due to lack of experiance with such things) up until now all has gone well but this has beaten me.

Here is the LISP code
(defun c:openxl (/ lst)
(acet-error-init (list '("cmdecho" 0) T))
(if (setq lst (acet-openxl-ui nil))
(acet-openxl (car lst) (cadr lst))
);if
(acet-error-restore)
);defun c:openxl
(setvar "tilemode" 0)
(setvar "filedia" 0)
(setvar "cmddia" 0)
(command "regenall" )
(setq a (command "script" "Iso2.scr" ))
(setvar "filedia" 1)
(setvar "cmddia" 1)
(princ)

and here is the .SCR it points to
start
EXCEL.EXE "C:\Users\majhu\CAD\Iso Info\Cad 1\Iso.csv"

I dont have a copy of BricsCAD as my trial version ran out so I can't continue to experiment and I dont even have a copy at work as I am no longer part of the CAD division, however, the two people who are have no idea or interest and i get called in to set everything up and resolve any issues, they also dont believe in the phrase "just google it", so to maintain my title as miricle worker I require a little help.
many thnaks
Matt

Comments

  • Its_Alive
    edited January 2020

    I'd use ActiveX, I.e.

    (defun OpenExcel (file / book exl)
    (setq exl (vlax-get-or-create-object "Excel.Application"))
    (vla-put-visible exl :vlax-true)
    (setq book (vla-open (vlax-get-property exl "WorkBooks") file))
    )

    (OpenExcel "C:/Temp/Temp.xlsx")

  • thank you for the help, do I replace (OpenExcel "C:/Temp/Temp.xlsx") with (OpenExcel "location of the file")? I have activated ActiveX in Excel but once again Excel opens but not the specific file.

  • Correct, it should be (OpenExcel "PATH to your file") . I’ve added a catch to output any error messages

    (defun OpenExcel (file / book exl)
    (setq exl (vlax-get-or-create-object "Excel.Application"))
    (vla-put-visible exl :vlax-true)
    (setq book (vl-catch-all-apply 'vla-open (list (vlax-get-property exl "WorkBooks") file)))
    (if (vl-catch-all-error-p book)
    (print (strcat "An error occurred: " (vl-catch-all-error-message book)))
    )
    )

  • Its_Alive
    edited January 2020

    Also, I noticed your path may be incorrectly formatted

    "C:\Users\majhu\CAD\Iso Info\Cad 1\Iso.csv" should be "C:/Users/majhu/CAD/Iso Info/Cad 1/Iso.csv"
    or"C:\\Users\\majhu\\CAD\\iso Info\\Cad 1\\Iso.csv"

    edit: the forum changes the text, just something to look out for

  • Thank you so much Daniel, it was the pathway, the original is what windows supplied when clicking on it.
    Many thanks

  • Hi Daniel, been a while but wondered if you could help, I now have a copy of bricscad and have got everything up and running including autoloading all my lisp routines when I open a drawing. the issue is however that they all run when opening a drawing and the which means I have all sorts going on and the excel file also opens, any ideas (even if its how to stop excel opening until I need it)?

  • Note that, in addition to the forum, you can also at any time file a support request with your Lisp questions - https://bricsys.com/protected/support/NewSupportRequest.do?categoryID=63