OLEObject.Add Excel Workbook!

(/iropracy

New Member
Joined
Nov 11, 2011
Messages
3
Hey everyone -

I have never had to come to a forum to find help... but here we are. I appreciate your responses.


I am simply trying to replicate the following actions in excel using VBA:
  • Insert > Object
  • Create from File
  • Display as Icon
  • Browse
  • Choose Excel File
I don't actually need the code to open a browse window and have a user choose the file... I just need to INSERT A FULL WORKBOOK! I already have the filepath.

This seems very easy... but excel keeps crashing when I try to do it. I keep getting the "Send Error Report - Excel has Crashed" window.

The error along with it is an automation error.

Run-time error '-2147417851 (80010105)
Automation Error
The server through an exception.

So let's look at the code.

Code:
Sub Embed()
Dim XLApp As Object 
Set XLApp = CreateObject("Excel.Application") 'Add an excel application so current excel won't crash
VFile = "C:\Documents and Settings\user\Desktop\Workbook.xls"
With XLApp
    .Workbooks.Add
    '**********
    Set oNewObj = .Workbooks(1).Sheets("Sheet1").OLEObjects.Add(Filename:=VFile, Link:=False, DisplayAsIcon:=True))
    '**********
End With
XLApp.Visible = True
End Sub

I have tried the code between the asterisks without adding a new application. I only add a new application so my current app will not crash. Can someone else try this code... is it my PC?

If vFile was a different filetype, say .doc, then it works. Anyone have thoughts?

Can someone either help me replicate the actions as described or help me with this error? I am very surprised... there are no threads on this.

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Works for me Windows7 Excel 2000

1. new xls
2. in module
3. Changed file name
4. Got rid of extra ")" in CreateObject
5. Ran the macro
OLE object pointing to the file was created

Sub Embed()
Dim XLApp As Object
Set XLApp = CreateObject("Excel.Application") 'Add an excel application so current excel won't crash
VFile = "C:\temp\simple.xls"
With XLApp
.Workbooks.Add
'**********
Set oNewObj = .Workbooks(1).Sheets("Sheet1").OLEObjects.Add(Filename:=VFile, Link:=False, DisplayAsIcon:=True)
'**********
End With
XLApp.Visible = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top