0

In relation to this answer I wrote to my previous question, I noticed with surprise that the Immediate Window is showing Microsoft Excel instead of PowerPoint (I was actually expecting to see the slide itself to be the parent of the group, since the macro is stating so). Could anyone please clarify why this is happening?

    Dim oSlide As slide: Set oSlide = oShpGroup.Parent
    Debug.Print Parent.name
Oran G. Utan
  • 455
  • 1
  • 2
  • 10
  • 1
    What is `Parent`? – GSerg Nov 19 '22 at 19:42
  • I thought it would be the "container" (the macro is running in PPT, with Excel closed) but your question is troubling me and I think I have to read through something. From here I understand it is how I thought, so I should see Microsoft PowerPoint, not Excel. I am confused. https://excelvbacode.wordpress.com/the-parent-property/ – Oran G. Utan Nov 19 '22 at 19:44
  • 1
    Put the caret inside the word `Parent` and press Shift+F2. Where does that bring you? – GSerg Nov 19 '22 at 19:47
  • It says "Cannot jump to 'Parent' because it is hidden", on top of the libraries and 'members of '. I am even more confused now... The same happens even if Excel is open. – Oran G. Utan Nov 19 '22 at 19:56
  • 1
    So [allow the display of hidden objects](https://stackoverflow.com/a/56122859/11683) in the object browser, then repeat the Shift+F2. – GSerg Nov 19 '22 at 20:00
  • I had a quick view, then realized that the Macro is in a file for which I activated the Excel Library, is it because of that? Still, the terminology is confusing I would say. – Oran G. Utan Nov 19 '22 at 20:05
  • When you "activated the Excel library", did you also move it in the list higher than the Powerpoint library? – GSerg Nov 19 '22 at 20:06
  • No, it's at the last position of those enabled: 1-Visual Basic For Applications 2-Microsfot PowerPoint 16.0 Library 3-OLE Automation 4-Microsoft Office 16.0 Office Library 5-Microsoft Excel 16.0 Object Library – Oran G. Utan Nov 19 '22 at 20:08
  • 1
    Still, where does the Shift+F2 bring you with the hidden objects displayed? – GSerg Nov 19 '22 at 20:11
  • `Property Parent As Application read-only Member of Excel.Global` `Library Excel C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE Microsoft Excel 16.0 Object Library` Could this cause some malfunctioning or is it normal and I just have to study more? – Oran G. Utan Nov 19 '22 at 20:14
  • 2
    Which would be because `Microsoft PowerPoint 16.0 Object Library` does not have a member called `Parent` in its `_Global` module, whereas `Microsoft Excel 16.0 Object Library` does. So your stray `Parent` resolves to `Excel._Global.Parent` because there isn't `PowerPoint._Global.Parent` for it to resolve to. – GSerg Nov 19 '22 at 20:22
  • 1
    Thank you, I will have to read some material to better understand what all this means, ` Debug.Print oShpGroup.Parent.name` showed me `Slide4` while the macro is running in Slide 2, and the same if I create a blank file with only one slide (which is not using Layout number 4). ??? – Oran G. Utan Nov 19 '22 at 20:59
  • 1
    Objects in PPT are in a hierarchy: Application | Presentations Collection | Presentation | Slides collection | Slide | Shapes collection. You've started with a reference to a Shape, it's parent object would be the Slide that the shape is on. To move up the chain to the application object, you'd look for oSlide.Parent.Parent.Parent – Steve Rindsberg Nov 19 '22 at 22:01
  • @SteveRindsberg, thank you, this clarifies further. I have redone the process: created a new file with new shapes, and their slide.Parent was correctly Slide1. So it seems like the shapes keep memory of the slide they come from for ever. I mean, they were showing slide 4 because, with all the experiments and cloning of slides I had made, they were still referring to the slide were they were created, which moved to the fourth place of the presentation. Although this may be just a curiosity, could it not be an issue in certain cases? – Oran G. Utan Nov 19 '22 at 22:42
  • This is the Automation Standard at *All objects, including the Application object and collection objects, must provide the following properties: `Application` VT_DISPATCH Returns the Application object; read only. `Parent` VT_DISPATCH Returns the creator of the object; read only. **Note** The Application and Parent properties of the Application object return the Application object.* from https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms221160(v=vs.85). The Application object and it properties and methods are global. So `Parent` means `Application.parent`. – Lundt Nov 20 '22 at 00:19
  • This is the other standard properties of a `Application` object. https://learn.microsoft.com/en-us/previous-versions/windows/desktop/automat/using-the-application-object-in-a-type-library. *The Application object should have the properties listed in the following table. The Application, FullName, Name, Parent, and Visible properties are required; other properties are optional.* and *The Application object should have the following methods. The Quit method is required; other methods are optional.* – Lundt Nov 20 '22 at 00:27
  • Just in case you aren't clear - the `application` object refers to the application hosting the VBA language. – Lundt Nov 20 '22 at 07:07
  • @Lundt, thank you. So `Parent VT_DISPATCH Returns the creator of the object` would mean it keeps memory of where the object was created, thus explaining why it was saying Slide4 instead of where the shapes were located. – Oran G. Utan Nov 20 '22 at 13:50
  • I suspect the presentation is corrupt or your code isn't asking the right question; a shape's .Parent should always return a reference to the slide the shape is *currently* on. You might want to edit your original post to show the code you're currently using. – Steve Rindsberg Nov 20 '22 at 20:12
  • @SteveRindsberg It was definitely something wrong with the file, I did all on a new file and the .Parent was the correct slide. It seems like PPT gets corrupted quite easily, or maybe three days of experimentation messed it up very well. The code is the one from the previous question, linked above with only this addition `Debug.Print oShpGroup.Parent.Parent.name: Debug.Print oShpGroup.Parent.name` – Oran G. Utan Nov 21 '22 at 17:46

0 Answers0