Results 1 to 3 of 3

OLEObject.Add Excel Workbook!

This is a discussion on OLEObject.Add Excel Workbook! within the Excel Questions forums, part of the Question Forums category; Hey everyone - I have never had to come to a forum to find help... but here we are. I ...

  1. #1
    New Member
    Join Date
    Nov 2011
    Posts
    3

    Default OLEObject.Add Excel Workbook!

    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!

  2. #2
    Board Regular
    Join Date
    Nov 2011
    Posts
    1,061

    Default Re: OLEObject.Add Excel Workbook!

    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

  3. #3
    New Member
    Join Date
    Nov 2011
    Posts
    3

    Default Re: OLEObject.Add Excel Workbook!

    Thanks... I have XP and Excel 2000. This is not a code problem then.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com