none
Excel VBA OLEObject.Add RRS feed

  • Question

  • Dear All,

    I am using the following VBA code to embed PDF (non-linked) into an Excel file

    ActiveSheet.OLEObjects.Add(Filename:=FilePath, Link:=False, DisplayAsIcon:=True, IconFileName:="C:\Windows\system32\packager.dll", IconIndex:=0, IconLabel:=IconName).Select

    In our office everybody is using O365 so the EXCEL version we are using is the same (I checked). BUT still there are 3 different outcomes for the above mentioned VBA code:

    a) Embedded file appears and the appearing name of the icon is the string defined as IconName

    b) Embedded file appears, but there is no icon, a differen Logo appears and the appearing name of the embedded file is a temporary name given by the system like 6DC40FF5.pdf

    c) Run-time error 1004 massage appears and the macro stops

    How is it possible that the same VBA coded (using the same Excel versions) results in 3 different outcomes?

    Any idea for solution?

    Thanks a lot

    Peter

    Monday, September 7, 2015 2:53 PM

Answers

  • Hi Peter,

    Based on the code abolve, it should dispaly the new OLE object either as an icon or as its regular picture.

    >>b) Embedded file appears, but there is no icon, a differen Logo appears and the appearing name of the embedded file is a temporary name given by the system like 6DC40FF5.pdf<<

    The issue is relative to the icon file instead of Office. Did you same operating system on the different computer? And I suggest that you check icon file to see whether it exits and to ensure the dll contain same icon.

    >>c) Run-time error 1004 massage appears and the macro stops<<

    The 1004 run-time error messages mean application-defined or object-defined error. This message is displayed when an error generated with the Raise method or Error statement doesn't correspond to an error defined by Visual Basic for Applications. It is also returned by the Error function for arguments that don't correspond to errors defined by Visual Basic for Applications. Thus it may be an error you defined, or one that is defined by an object, including host applications like Microsoft Excel, Visual Basic, and so on.

    Please ensure that you can insert the file manually when you get this error message. So that it can also works for the macro. You can get more detail about this error from link below:
    Application-defined or object-defined error

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 10, 2015 8:26 AM
    Moderator

All replies

  • Hi Peter,

    This is the forum to discuss questions and feedback for Microsoft Excel, I'll move your question to the MSDN forum for Excel

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Emi Zhang
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs. Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, September 8, 2015 6:04 AM
  • Hi Emi,

    thanks for your help. But something is not clear for me. You have already moved this question to the MSDN forum or I have to do it? Based on the link inserted in your answer I have tried to find my question, but I couldn't.

    Thanks a lot

    Peter

    Tuesday, September 8, 2015 2:19 PM
  • Hi Petya,

    I have moved your question to MSDN Forum.

    Regards,

    Emi Zhang
    TechNet Community Support


    It's recommended to download and install Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office programs. Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.


    Wednesday, September 9, 2015 1:21 AM
  • Hi Peter,

    Based on the code abolve, it should dispaly the new OLE object either as an icon or as its regular picture.

    >>b) Embedded file appears, but there is no icon, a differen Logo appears and the appearing name of the embedded file is a temporary name given by the system like 6DC40FF5.pdf<<

    The issue is relative to the icon file instead of Office. Did you same operating system on the different computer? And I suggest that you check icon file to see whether it exits and to ensure the dll contain same icon.

    >>c) Run-time error 1004 massage appears and the macro stops<<

    The 1004 run-time error messages mean application-defined or object-defined error. This message is displayed when an error generated with the Raise method or Error statement doesn't correspond to an error defined by Visual Basic for Applications. It is also returned by the Error function for arguments that don't correspond to errors defined by Visual Basic for Applications. Thus it may be an error you defined, or one that is defined by an object, including host applications like Microsoft Excel, Visual Basic, and so on.

    Please ensure that you can insert the file manually when you get this error message. So that it can also works for the macro. You can get more detail about this error from link below:
    Application-defined or object-defined error

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, September 10, 2015 8:26 AM
    Moderator