locked
An Embedded Word Fails to Fire OleObject Events And Word Document Events RRS feed

  • Question

  • hi, i have an Excel worksheet with an embedded macro-enabled Word document, as icon. 

    OLEObject Events:

    The Excel VBA Object Browser lists a "GotFocus" event, but this does not work.

    The oleObject is not available in the VBA Object picker (where objects supporting events, such as "Worksheet", are listed). 

    The code below fails:

    ===
    In Workbook module:

    Private Sub Workbook_Open()
              Set Sheet1.oDoc = Sheet1.OLEObjects(1)
    End Sub

    ===
    In Worksheet module:

    Public WithEvents oDoc As OLEObject

    ===

    When the above Workbook_Open event tries to execute "Set Sheet1.oDoc = ...", i get "Object or class does not support the set of events"

    ===

    Word Document Events:

    The embedded Word doc contains vba:

    ===
    ThisDocument module:

    Private Sub Document_Open()
              MsgBox "open"
    End Sub

    ===

    The Document_Open event in the embedded Word doc does not fire when the doc is opened. 

    Thx for any help!

    • Edited by johny w Sunday, February 21, 2016 9:16 PM
    Sunday, February 21, 2016 9:10 PM

Answers

  • Hi johny,

    >> The Excel VBA Object Browser lists a "GotFocus" event, but this does not work

    I made a test with your description, and I got the same result with you. With the links below, an ole object could be an ActiveX control or a linked or embedded OLE object on a worksheet, but OLEObject.GotFocus occurs only when an ActiveX control gets input focus. So I think embedded OLE object is not support GotFocus.

    #OLEObject Object (Excel)
    https://msdn.microsoft.com/en-us/library/office/ff838421.aspx
    #OLEObject.GotFocus Event (Excel)
    https://msdn.microsoft.com/EN-US/library/office/ff195806.aspx

    >> The Document_Open event in the  embedded Word doc does not fire when the doc is opened

    I made a test with your description, and I could reproduce this issue. I assume it is related with how OleObject open the document. But I found nothing information about this by researching. And I found that if I add a button with macro in document, it did not work either, and the title of the documents which is opened by clicking oleobject in excel, the title is not the same with embedded file. I assume oleobject did not open the same file you embedded in excel file.

    Best Regards,

    Edward


    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.


    Monday, February 22, 2016 10:08 AM
  • Hi johny,

    >>macros seem to run ok, just not events

    Yes, I agree with you. With testing, MacroButton is worked, and all the other events of document would not fire when it is an embedded word document in excel. And I found the Document_Open fires only when you insert the word document first time.

    Best Regards,

    Edward


    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.


    Tuesday, February 23, 2016 2:03 AM

All replies

  • Hi johny,

    >> The Excel VBA Object Browser lists a "GotFocus" event, but this does not work

    I made a test with your description, and I got the same result with you. With the links below, an ole object could be an ActiveX control or a linked or embedded OLE object on a worksheet, but OLEObject.GotFocus occurs only when an ActiveX control gets input focus. So I think embedded OLE object is not support GotFocus.

    #OLEObject Object (Excel)
    https://msdn.microsoft.com/en-us/library/office/ff838421.aspx
    #OLEObject.GotFocus Event (Excel)
    https://msdn.microsoft.com/EN-US/library/office/ff195806.aspx

    >> The Document_Open event in the  embedded Word doc does not fire when the doc is opened

    I made a test with your description, and I could reproduce this issue. I assume it is related with how OleObject open the document. But I found nothing information about this by researching. And I found that if I add a button with macro in document, it did not work either, and the title of the documents which is opened by clicking oleobject in excel, the title is not the same with embedded file. I assume oleobject did not open the same file you embedded in excel file.

    Best Regards,

    Edward


    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.


    Monday, February 22, 2016 10:08 AM
  • "I found that if I add a button with macro in document, it did not work either,"

    @EdwardZ, i am able to put a button-field in the document and manually run a macro with it. 

    When you embed your Word doc into Excel, be sure to pick "macro-enabled Word document", and check in "Show as icon". 

    Open the Word doc, and create a public sub:

    public sub Test
    Msgbox "Test"
    end sub

    In Word doc, click Insert ribbon > Quick Objects > Field > MacroButton. Select "Test" in "Macro name". 

    In the doc, double-click the new field you just created. You will get the "Test" message-box. 

    So, macros seem to run ok, just not events. 

    Any other Word-VBA-OLE experts out there?

    thx!

    Monday, February 22, 2016 8:04 PM
  • Hi johny,

    >>macros seem to run ok, just not events

    Yes, I agree with you. With testing, MacroButton is worked, and all the other events of document would not fire when it is an embedded word document in excel. And I found the Document_Open fires only when you insert the word document first time.

    Best Regards,

    Edward


    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.


    Tuesday, February 23, 2016 2:03 AM