PDA

View Full Version : VBA Error when inserting file into Word



paddysheeran
03-23-2012, 04:15 AM
Hi All,

I now use Excel 2010 and have been getting a error message when running a piece of code:

wdDoc.Activate

Set t = wdDoc.Bookmarks("Section10_File").Range

t.InlineShapes.AddOLEObject ClassType:="Excel.Sheet.12", Filename:= _
GlobalFolder & "Device Compliance Audit.xlsx" _
, LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{90120409-6000-11D3-8CFE-0150048383C9}\xlicons.exe" _
, IconIndex:=1, IconLabel:="Section 10 Data"


The Error message is:

"The program used to create this object is Excel. That program is either not installed on your computer or it is not responding. To edit this object, install Excel or ensure that any dialog boxes in Excel are closed"

When the error appears I have to click OK. I then get a the debug error message:

Run-time error '4198': Command Failed

When I then press debug the following is highlighted:

t.InlineShapes.AddOLEObject ClassType:="Excel.Sheet.12", Filename:= _
GlobalFolder & "Device Compliance Audit.xlsx" _
, LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{90120409-6000-11D3-8CFE-0150048383C9}\xlicons.exe" _
, IconIndex:=1, IconLabel:="Section 10 Data"

If I then press the Continue Button (F5) without any amendments the rest of the code runs through to completion even though I have 3 other identical pieces of code (to insert files) that run through without any other errors.

So my issue is why this error message presents itself/what can be done to stop this from happening. If it cant is there any other way to insert files into my word document?

many thanks in advance.

Paddy.

paddysheeran
03-26-2012, 03:08 AM
Bump.

GTO
03-26-2012, 04:57 AM
Just a stab, try changing ClassType:="Excel.Sheet.12" to 14, as I think that is what 2010 is.

If that doesn't work, I'd suggest attaching a workbook and document (zipped) to replicate the error.

Mark

paddysheeran
03-26-2012, 06:55 AM
changing to Excel.sheet.14 has no effect on the error. I have other excel files in the script that attach (they are excel.sheet.8) without a problem.

Kenneth Hobs
03-26-2012, 07:16 AM
Are you sure that the path to the xlicons.exe exists?

On my winxp excel 2010 the path is:
C:\WINDOWS\Installer\{90140000-0011-0000-0000-0000000FF1CE}\xlicons.exe