FoxPro Programming
Having problems with office automation
Gravatar is a globally recognized avatar based on your email address. Having problems with office automation
  Randolph
  All
  Oct 1, 2020 @ 07:15am

Hi all, Thanks for adding me to this message board. I have a question regarding some problem I have encountered with office automation using office 2019.

I create the following script regarding creating excel object.

oExcel = CreateObject("Excel.Application")
if vartype(oExcel) != "O"
  * could not instantiate Excel object
  * show an error message here
  return .F.
endif

when executing the following command:

oExcel.Visible = .T.

I will get the following error: error 1923 MESSAGE: Object Excel not found

Question: What is causing this issue.... any help is highly appreciated

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Rick Strahl
  Randolph
  Oct 1, 2020 @ 02:12pm

In the future please mark up your code snippets in your posts so we can read your code. There's a very clear note above the Post Message button that asks you to format your code!

It seems pretty clear that the Office automation objects are not installed or registered on your machine. Are you sure Office and Excel are installed? If it is you may have to reinstall to make sure the application is properly registered.

Note also that Machine Policy may affect what COM objects you can instantiate. It's possible that the MS Office objects are not allowed access. You can look in DCOMCNFG to see what permissions are required to instantiate Excel.Application.

You can get to DCOMCNFG via Component Services on the local machine:

MMC comexp.msc
MMC comexp.msc /32 

Search for Microsoft Excel in the long list of registered DCOM components. Not sure which one applies the 32 bit or 64 bit version - you might have to check both. Then check for Launch permissions. If it says default, check the default launch permissions on the Machine node.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Richard Kaye
  Rick Strahl
  Oct 2, 2020 @ 05:21am

You need the full 32 bit desktop version installed to do any COM automation with Office apps.

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Rick Strahl
  Richard Kaye
  Oct 2, 2020 @ 12:48pm

Are you sure about that?

Office servers are Out of Process COM servers and so it shouldn't matter whether the server is 32 or 64 bit. On my machine I'm running Office 365 with whatever the default is and it appears that's the 64 bit version, and I can access Excel no problem via COM.

I think the most likely issues for not working are:

  • Not actually installed
  • DCOM Permissions blocked by Machine Policy

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Richard Kaye
  Rick Strahl
  Oct 2, 2020 @ 01:50pm

As far as automation from VFP is concerned, pretty sure. AFAIK those COM interfaces only get installed when you do a full 32 bit desktop install. And there were issues with selecting the 1st time used option IIRC. But maybe Microsoft has changed that in more recent versions of Office.

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Rick Strahl
  Richard Kaye
  Oct 4, 2020 @ 11:11pm

All I know I just installed Office 365 - no special options. Version shows 64-bit and automation works for me.

I do see entries in DCOMCNFG for both 32-bit and 64-bit, so that might be why it's working. But regardless - recent versions of Office seem to definitely work with automation from VFP regardless of whether you're using 32 bit or 64 bit.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Having problems with office automation
  Richard Kaye
  Rick Strahl
  Oct 5, 2020 @ 08:09am

Sounds like they must have changed how/when the COM interfaces get installed. Good for Microsoft making things easier rather than harder...

© 1996-2024