TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mikosalm on September 26, 2019, 01:10:23 PM

Title: Unable to create Excel Object
Post by: Mikosalm on September 26, 2019, 01:10:23 PM
Hi Everyone,

I am having trouble creating an excel object. The below line works on all of our workstations except one in which it returns nil.

Code: [Select]
(setq xl (vlax-get-or-create-object "Excel.Application"))
Excel is installed on the computer and I can open the workbook manually. Anyone know how to correct this?
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 01:48:22 PM
The specified progid is incorrect, like missing a version number. e.g. "Excel.Application.14".

See this (http://www.theswamp.org/index.php?topic=52397.msg573363#msg573363) thread.

Cheers.
Title: Re: Unable to create Excel Object
Post by: Mikosalm on September 26, 2019, 02:11:44 PM
Thanks for the response MP

The proid works without the version number on other similar workstations so I am not sure why it would be needed here.

Tried it anyways though and it still returns nil. Using Office 2016 so I tried "Excel.Application.16" as well as what you suggested.
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 02:35:03 PM
Did you try the utility I referenced, e.g. (mapcar 'print (_FindProjIDs "*excel*")) and if so what was the result?
Title: Re: Unable to create Excel Object
Post by: Mikosalm on September 26, 2019, 03:53:23 PM
Hey MP,

This was the returned result: "AdobePDFMakerX.ExcelSheetsDlg" ("AdobePDFMakerX.ExcelSheetsDlg")
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 03:57:43 PM
Surely more than that was returned, especially if excel is installed as you say.
Title: Re: Unable to create Excel Object
Post by: jtoverka on September 26, 2019, 04:04:03 PM
Did you try the utility I referenced, e.g. (mapcar 'print (_FindProjIDs "*excel*")) and if so what was the result?

I used that utility a few weeks ago to find all possible progids to use in autocad (used "*"). I tested vlax-create-object on each one. Not all of them worked, some returned errors, others simply nil. A couple of them took so long to create it was like an infinite loop.

Surely more than that was returned, especially if excel is installed as you say.

What if there is a case where you can have excel installed, but activeX is disabled?
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 04:13:40 PM
Not all progids are associated with an application executable, nor are all instantiable.

I can’t speak to an AutoCAD instance where ActiveX has been disabled because I’ve not encountered that scenario.

Cheers.
Title: Re: Unable to create Excel Object
Post by: Mikosalm on September 26, 2019, 06:17:21 PM
Quote
Surely more than that was returned, especially if excel is installed as you say.

What's the expected result? I am getting the above on a workstation which can create an Excel object as well.

I can see that Excel is in the registry and I am also able to create objects for other Office applications like Outlook.
Code - Auto/Visual Lisp: [Select]
  1. (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\Office")

("Word" "Teams" "PowerPoint" "Outlook" "OneNote" "Lync" "Excel" "DmsClient" "Common" "8.0" "16.0" "15.0" "14.0" "12.0" "11.0")

Quote
What if there is a case where you can have excel installed, but activeX is disabled?

Wouldn't that prevent macro's from running as well? Excel appears to be fully functional.
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 07:19:09 PM
I'd expect to see a list of matching progids for a spec of "*excel*", something like:

        "Excel.Application.14"
        "Excel.Chart.5"
        "Excel.Chart.8"
        "Excel.ChartApplication.14"
        "Excel.OpenDocumentSpreadsheet.12"
        "Excel.Sheet.12"
        "Excel.Sheet.5"
        "Excel.Sheet.8"
        "Excel.SheetBinaryMacroEnabled.12"
        "Excel.SheetMacroEnabled.12"
        "ExcelAddIn.Connect.15"
        "ExcelAddIn.Connect.5"
        "ExcelChart"
        "ExcelMacrosheet"
        "ExcelWorksheet"
        "VS15ExcelAdaptor.1"
   
Not:

        "AdobePDFMakerX.ExcelSheetsDlg"

Don't know what to tell you.
Title: Re: Unable to create Excel Object
Post by: Mikosalm on September 26, 2019, 09:57:24 PM
Turns out the error was unrelated to AutoCAD. It was fixed by repairing the Office install.

Unsure why your function isn't working though.

Thank you for the responses.
Title: Re: Unable to create Excel Object
Post by: MP on September 26, 2019, 10:03:27 PM
I respectfully submit - the function works - your registry is/was wack - glad you appear to have it sorted.
Title: Re: Unable to create Excel Object
Post by: AthenaBonilla on May 07, 2023, 10:13:16 PM
Hi. I had the same problem with Excel a few days ago. I'm really sorry for bumping. Just need your help.
Title: Re: Unable to create Excel Object
Post by: BIGAL on May 08, 2023, 03:34:51 AM
With excel 2 scenarios is open or is not

Code: [Select]
(or (setq myxl (vlax-get-object "Excel.Application"))
    (setq myxl (vlax-get-or-create-object "excel.Application"))
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
Title: Re: Unable to create Excel Object
Post by: RishiRamos on May 09, 2023, 07:46:38 PM
Hey. Have you tried updating your Office version to the latest one? That might solve the issue. By the way, have you checked out Office 2021 Professional Plus for Windows? It's the latest and greatest version with all the bells and whistles. I'm new on this forum, but I can tell you that turnkeypoint.com (https://turnkeypoint.com/product/office-2021-professional-plus-for-windows/) is a great resource for all things tech-related. Hope this helps!
Title: Re: Unable to create Excel Object
Post by: liuhe on May 09, 2023, 11:30:48 PM
(and (setq GGG
                        (vl-registry-read
                           "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Excel.EXE"
                           "Path"
                        )
                  )
                  (setq GGG (strcase (strcat GGG "Excel.EXE" )))
            )