Open Excel file from ACAD

Open Excel file from ACAD

wales123456
Contributor Contributor
5,453 Views
10 Replies
Message 1 of 11

Open Excel file from ACAD

wales123456
Contributor
Contributor

Hi everyone

 

I am trying to open a drawing register from inside acad and the following is the code I have so far:

 

(defun c:rg (/ path filename program)
  (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
        path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
  )
  (setq filename (strcat path "\"QCL Issue Register.xlsm")
  (setq program "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE")
  (startapp program filename))
(princ))

 

Could someone please advise why it isn't working?

0 Likes
Accepted solutions (1)
5,454 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Hi everyone

 

I am trying to open a drawing register from inside acad and the following is the code I have so far:

 

(defun c:rg (/ path filename program)
  (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
        path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
  )
  (setq filename (strcat path "\"QCL Issue Register.xlsm"))
  (setq program "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE")
  (startapp program filename)😉
(princ))

 

Could someone please advise why it isn't working?


Try it like this.

Check the path, I have no root in mine. 

You have too many or missing parenthesis, \\ wrong.... see the red ones.

 

(defun c:rg (/ path filename program)
  (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
        path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
        )
  (setq filename (strcat path "\\QCL Issue Register.xlsm"))
  (setq program "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\EXCEL.EXE")
  (startapp program filename)
  (princ))

 

0 Likes
Message 3 of 11

wales123456
Contributor
Contributor

Thanks for your swift response BeekeeCZ

 

I now have this as the code

(which I think is what you have advised)

 

(defun c:rg (/ path filename program)
(vl-load-com)

  (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
        path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
  )
  (setq filename (strcat path "\"QCL Issue Register.xlsm"))
  (setq program "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE")
  (startapp program filename)
(princ))

 

but acad gives me the following error when I load the lisp in:

 

too few arguments in SETQ: (SETQ PATH (VL-STRING-RIGHT-TRIM "\\" (GETVAR (QUOTE DWGPREFIX))) Â PATH (SUBSTR PATH 1 (VL-STRING-POSITION (ASCII "\\") PATH 0 T)))

 

any ideas?

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant

Please read my previous answer again and fix it.

 

Little modified version, but never received your error.

 

(vl-load-com)

(defun c:rg (/ path filename)
  (if (findfile (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
                      path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
                      filename (strcat path "\\QCL Issue Register.xlsm")))
    (startapp "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE" filename)
    (princ "\n'QCL Issue Register' File not found."))
(princ))
0 Likes
Message 5 of 11

wales123456
Contributor
Contributor

Thanks BeekeeCZ

 

The LISP works now but when it opens excel, it tries to open K:\Projects\2016.xlsx

, then tries to open Projects\16899.xlsx, then New.xlsx, then Road.xlsx, etc..

 

The drawing is located here:

 

K:\Projects\2016 Projects\16899 New Road Residential\Draw\C-121 Location Plan.dwg

 

Do I need to put double quotation marks in as there are spaces in the folder names? Or is it something to do with the path variable?

 

Thanks again.

 

 

0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant
I need the relation between dwg and xls file.
So you gave me dwg path.
Where is your QCL Issue Register.xlsm located?
0 Likes
Message 7 of 11

wales123456
Contributor
Contributor

K:\Projects\2016 Projects\16899 New Road Residential\QCL Issue Register

0 Likes
Message 8 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

Yes, you're right. Needs to be wrapped in quote marks.

 

(vl-load-com)

(defun c:rg (/ path filename)
  (if (findfile (setq path (vl-string-right-trim "\\" (getvar 'dwgprefix))
                      path (substr path 1 (vl-string-position (ascii "\\") path 0 T))
                      filename (strcat "\"" path "\\QCL Issue Register.xlsm\"")))
    (startapp "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE" filename)
    (princ "\n'QCL Issue Register' File not found."))
(princ))
Message 9 of 11

wales123456
Contributor
Contributor

perfect

 

thank you very very much. I really appreciate it.

 

(do I give you Kudos as well as accept as solution?)

0 Likes
Message 10 of 11

ВeekeeCZ
Consultant
Consultant

You should definitely mark the final answer as the solution if it solve your problem - it's a technical thing.

Kudos are more about emotions, if you were pleased.... see the VIDEO. Actually I've saw that now for the first time - It was just as a text before...

0 Likes
Message 11 of 11

Ranjit_Singh
Advisor
Advisor

Just a suggestion that do not hard code the path of the application. If you went to office 14 or 20 or something else in future; or you got rid of root or something of that sort, it may not work. As @ВeekeeCZ pointed out he did not have root on his computer. I was testing on mine and I still have Office 14.