Automation/WebClayStation Create Document Errors
Symptoms: When using an Automation or the WebClayStation client to create a Word/Excel/PDF/MHTML document either from a document template or when exporting data, the logs show errors such as “Could not create the Microsoft Office application object”, “ActiveX can't create Object” or “Automation Error”, or “Object not set”. However, when generating the same document using a desktop Clay client like ClayStation, it works. I.e. it only fails when running from a Windows Service like ClayCentral or WebClayStation.
Explanation: This is a fairly common problem that has to do with running Microsoft Office from a Windows Service. Since WebClayStation and ClayCentral both run as a Windows Service, and run as the Windows 'System' user, it is possible that this user does not have the correct permissions or resources that it needs for running Office applications. Clay currently depends on Microsoft Office to convert HTML documents to Word/Excel/PDF/MHTML and therefore requires a working installed instance of Office for this task.
Note that Clay has been tested successfully with all versions of Office (as of this update: 2013/2016/2019 and Office 365), both 32bit and 64bit, whether running as System or as another user, and all have worked. So it is usually a machine-specific or permission issue.
Sometimes, however, this functionality may break with Microsoft updates to either Windows and/or Office. For example, specifically, an updated version of Windows 10 in late 2020 combined with Office 2016/2019/365 also updated in 2020, did not work. Clay servers (ClayCentral & WebClayStation) still work with an updated Windows Server & Office, however. See the Solutions below for solving the issue with Windows 10.
Testing methods:
- Make sure the exact same template and output format works when generated via a desktop Clay client like ClayStation.
- Change the Windows Service (WebClay or ClayCentral) to run as a different Windows user by changing its logon settings in the Windows Service Properties window (it usually requires a user that has a password set). If it works, this proves that it is a Windows permission or user-related Office issue. Note that in order to use this as a permanent solution or work-around, you have to ensure that the user will never have its password expired or be inactivated.
- You can also test whether Office works for the 'System' user by running Word as the System user. One method for testing is to use the psexec tool: “psexec -i -s “c:\<pathtoword>\winword.exe” (where <pathtoword> is the full path to the exe). psexec is a tool included in the pstools available on the internet.
- Note that if the problem is a DCOM error (see below for solutions), errors will appear in the Windows Event Log under “System” for the DistributedCom” component.
Solutions:
- On Windows 7 and higher there is a known issue with the automation of Excel/Word. A workaround is to create the following folders: “\Windows\SysWOW64\config\systemprofile\Desktop” - and: “Windows\System32\config\systemprofile\Desktop”. Also ensure that the process in question has full permissions to these folders (e.g. the 'System' user).
- For Office 2019/2016/365 especially, and perhaps other versions of Office, try the following workarounds:
- Open the “Component Services” control panel (comexp.msc). (For 32bit office you may need to run the 32bit version using “MMC comexp.msc /32”).
- Navigate to Console Root/Component Services/Computers/My Computer/DCOM Config
- Find both “Microsoft Word 97 - 2003 Document” and “Microsoft Excel Application” and apply one of the following changes to both of these components:
- Right Click/Properties and in the 'Identity' tab select one of the following:
- (This solution is only appropriate on a computer where somebody is always actively logged in to Windows. I.e. it is not appropriate on server machines. This does solve the problem when installing ClayCentral or WebClayStation on a personal computer however): Select “The interactive user” and press OK.
- (This solution may not work with newer broken versions of Office): Select “This user”, enter a username and password, and press OK. Note that the user must be a Windows user whose password will not expire and which will not be inactivated.
- If you are using a different Windows user for Clay servers other than the default System user, it may be necessary to also add permissions in the Security tab (typically only if that user doesn't have administrator access).
- Make sure that the installation for Microsoft Office has been finalized by running Word/Excel on the server machine at least once. See above on how to test this for the System user. Note that Clay should work even if Office has not been activated yet but it does require the application to be properly installed for the relevant Windows user.
- In several scenarios, upgrading or uninstalling and then re-installing Office may fix the issue. Alternatively, an older version of Office may work better if a Microsoft update broke it.