From within a form's code, how do I reference its owner? RRS feed

  • Question

  • My Word document opens a custom modeless dialog, which I assume is properly referred to as a form. I want the dialog to remain open so the user can select one of its controls that do something to the document. So, the code for the form has to be able to reference the document that opened it.

    If I use ActiveDocument, it works fine but only if the document is the only one open, its being the only active document. I have tried various things but nothing works.

    In the document's properties, I have given it a Name. IF within the form's code I use something like


    Word complains. Just doing Name.whatever also does not work. The form does not appear to have an owner property or something similar.

    Using the documents FILE name works, but the user may rename the file, and I see no way to capture that file name change. It seems as if one should, but I do not know how.

    Any help is appreciated. I am Word 2013, but the document needs to work in Word 2010 also.

    Thanks, Van

    Tuesday, June 24, 2014 4:41 PM

All replies

  • Hi VanFromBuffalo,
    How was that document you need to work on opened? If from your code you can set
    an object variable to it and use that.
    A document from the Documents collection can only be accessed through either
    its index number or its filename.
    Alternatively, you can loop through all open documents and test for a
    characteristic of the document you need.

    Regards, Jan Karel Pieterse|Excel MVP|
    Wednesday, June 25, 2014 9:41 AM
  • Thanks Jan,

    I figured it out. I needed the dialog to call a procedure of the document that created the dialog. I made THAT procedure Public, and then called it from the dialog using the Name property of the document, NOT its file name, something like:



    Wednesday, June 25, 2014 1:27 PM