rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 301 forks source link

Can't rename slide in Powerpoint #5033

Open SmileyFtW opened 5 years ago

SmileyFtW commented 5 years ago

Rubberduck version information Version 2.4.1.4742 OS: Microsoft Windows NT 10.0.17134.0, x64 Host Product: Microsoft Office x86 Host Version: 16.0.11629.20246 Host Executable: POWERPNT.EXE

Description Attempting to rename Slide1 (Slide1) in RD in PowerPoint doesn't rename the slide.

To Reproduce Steps to reproduce the behavior:

  1. Create a codebehind for a slide in a presentation so it will show up in CE
  2. Click on the slidename in CE
  3. In the lower panel of the CE click Rename
  4. Do the rename; click ok
  5. Refresh
  6. No change to the slide code name as it would in a worksheet in Excel

Expected behavior The codename of the slide would change and be displayed as "NewSlideName (SlideN)"

Log file RubberduckLog.txt

retailcoder commented 5 years ago

I'm not very familiar with VBA for PowerPoint - how do I get slides to even show up in the VBE's vanilla Project Explorer?

Slides not showing up as document modules in the VBA project could be a hint that something is special about them...

SmileyFtW commented 5 years ago

Hmmm. Was going to see if I could provide better and more complete info so I opened PP and Alt+F11. RD loads and opens. However, as with many cases I see RD as a collapsed window (#4858) and when trying to resize in any way crashes PP. Just tried in Excel and that crashes. RD .4901. Should I submit new issue or resurrect 4858? RubberduckLog.txt

daFreeMan commented 5 years ago

@SmileyFtW Try installing .4925.

FWIW, I haven't had any issues with RD in Access over the last several builds, but TBF I haven't written any PPT code in a long time.

retailcoder commented 5 years ago

@SmileyFtW "maximize", or double-clicking the VBE's title bar, crashes PPT? I can see drag-resizing interfering with docking, but maximizing the VBE mainwindow worked for me every time.

As for resurrecting 4858; as was noted, the weirdly-sized VBE mainwindow issue is more of an Office (Windows?) issue, since it has been seen happening in a vanilla VBE without Rubberduck installed.

SmileyFtW commented 5 years ago

OK. No resurrection. Yes, double clicking and maximizing with the thingie on the title bar both crash excel and pp. I am going to update to the latest RD. Do a restart on my machine and a repair on office to see if the issue goes away.

retailcoder commented 5 years ago

@SmileyFtW mind uninstalling RD and firing up PPT (or Excel) without RD before installing the latest pre-release build?

SmileyFtW commented 5 years ago

OK. No resurrection. Yes, double clicking and maximizing with the thingie on the title bar both crash excel and pp. I am going to update to the latest RD. Do a restart on my machine and a repair on office to see if the issue goes away.

Did a repair, computer restart, and installed RD 4925. I have 2 monitors, so I moved the excel window to the main monitor; then Alt+F11. VBIDE/RD shows in second monitor as before. Resize crashed Excel.

retailcoder commented 5 years ago

@SmileyFtW and everything goes back to normal without RD?

SmileyFtW commented 5 years ago

I had three add-ins load at startup: MZTools, PrettyCodePrint, and RD. I changed the settings to load only RD at startup. Restarted XL. No crash. So it must be one of the other 2 or a conflict of a combination. So I would say no RD issue WRT application crashing. Now back to getting a better answer.

retailcoder commented 5 years ago

Good to know! That said I still have no idea how you get a Slide document module in your PPT-VBA project.

SmileyFtW commented 5 years ago

I don't remember how I added a Slide document module in the file, yet there is one in the project that started the question.

So here's a screenshot: image

There is a "(Name)" Property. In Excel, as we know, the (Name) Property is the CodeName and the Name Property is the Tab Name. Apparently, the Name Property in PP doesn't exist, but the slide in both PE and CE appear to show one. PE doesn't show the (Name) Property.

I am sure you are right in that there must be something "special" about PP and its implementation. I added a second slide to see what would happen in CE and PE. Nothing. No new module in PowerPoint Objects or in RD. I expect I would have to remember how I added code behind and do it to the second slide before it would show up in either explorer.

SmileyFtW commented 5 years ago

This was frustrating, and it had me truly irritated that I had no idea how I got the slide object in the first place. DuckDuckGo got me nowhere. Finally, I stumbled onto the answer: 1) with the slide that has no code pane and is not in the VBIDE PE, go to the Developer tab in the Ribbon 2) add a control (I used a command button) 3) double-click the control 4) the code pane shows up with the default event handler Mystery solved for how I got the object to show up in the 1st place. My original question remains.

retailcoder commented 5 years ago

Apparently, the Name Property in PP doesn't exist, but the slide in both PE and CE appear to show one.

Not seeing it in the PE, but CE is showing it because we're not special-casing Excel worksheets & workbooks - we'll look for a Name property on any document module (now, perhaps we should not show the parenthesized "display name" when there's no Name property).

Anyway, repro confirmed, logging a bunch of exceptions:

2019-09-06 10:44:28.0087;ERROR-2.4.1.4924;Rubberduck.VBEditor.SafeComWrappers.SafeComWrapper`1;Unexpected exception while acquiring the host application object for application PowerPoint from a document module.;System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at Microsoft.Vbe.Interop.Property.get_Object()
   at Rubberduck.VBEditor.SafeComWrappers.Abstract.HostApplicationBase`1.ApplicationFromVbe(IVBE vbe, String applicationName) in C:\projects\rubberduck\Rubberduck.VBEEditor\SafeComWrappers\Abstract\HostApplicationBase.cs:line 59
2019-09-06 10:44:28.1367;ERROR-2.4.1.4924;Rubberduck.UI.CodeExplorer.Commands.RenameCommand;System.NotSupportedException: Object doesn't support this property or method
   at Microsoft.Vbe.Interop._Properties.Item(Object index)
   at Rubberduck.VBEditor.SafeComWrappers.VBA.Properties.get_Item(Object index) in C:\projects\rubberduck\Rubberduck.VBEditor.VBA\SafeComWrappers\VB\Properties.cs:line 24
   at Rubberduck.Refactorings.Rename.RenameRefactoring.RenameModule(RenameModel model, IRewriteSession rewriteSession) in C:\projects\rubberduck\Rubberduck.Refactorings\Rename\RenameRefactoring.cs:line 354
   at Rubberduck.Refactorings.Rename.RenameRefactoring.RefactorImpl(RenameModel model) in C:\projects\rubberduck\Rubberduck.Refactorings\Rename\RenameRefactoring.cs:line 71
   at Rubberduck.Refactorings.InteractiveRefactoringBase`2.Refactor(TModel initialModel) in C:\projects\rubberduck\Rubberduck.Refactorings\InteractiveRefactoringBase.cs:line 48
   at Rubberduck.UI.CodeExplorer.Commands.RenameCommand.OnExecute(Object parameter) in C:\projects\rubberduck\Rubberduck.Core\UI\CodeExplorer\Commands\RenameCommand.cs:line 58
   at Rubberduck.UI.Command.CommandBase.Execute(Object parameter) in C:\projects\rubberduck\Rubberduck.Core\UI\Command\CommandBase.cs:line 85;System.NotSupportedException: Object doesn't support this property or method
   at Microsoft.Vbe.Interop._Properties.Item(Object index)
   at Rubberduck.VBEditor.SafeComWrappers.VBA.Properties.get_Item(Object index) in C:\projects\rubberduck\Rubberduck.VBEditor.VBA\SafeComWrappers\VB\Properties.cs:line 24
   at Rubberduck.Refactorings.Rename.RenameRefactoring.RenameModule(RenameModel model, IRewriteSession rewriteSession) in C:\projects\rubberduck\Rubberduck.Refactorings\Rename\RenameRefactoring.cs:line 354
   at Rubberduck.Refactorings.Rename.RenameRefactoring.RefactorImpl(RenameModel model) in C:\projects\rubberduck\Rubberduck.Refactorings\Rename\RenameRefactoring.cs:line 71
   at Rubberduck.Refactorings.InteractiveRefactoringBase`2.Refactor(TModel initialModel) in C:\projects\rubberduck\Rubberduck.Refactorings\InteractiveRefactoringBase.cs:line 48
   at Rubberduck.UI.CodeExplorer.Commands.RenameCommand.OnExecute(Object parameter) in C:\projects\rubberduck\Rubberduck.Core\UI\CodeExplorer\Commands\RenameCommand.cs:line 58
   at Rubberduck.UI.Command.CommandBase.Execute(Object parameter) in C:\projects\rubberduck\Rubberduck.Core\UI\Command\CommandBase.cs:line 85
bclothier commented 5 years ago

How did you rename the slide to PracticeCardMemberSlide? Can't find it via PP's UI.

bclothier commented 5 years ago

FWIW. None of Microsoft's 4 Office Apps agree on how to display the document modules.

Excel: image

Access: image

Word: image

PPT: image

CE will have need to knock some heads and make them be more uniform. That was already done for Access, but not really for Word nor PPT.

In order to fix this, I think the CE will need to require a struct from document module, implemented by the respective IHostApplication, similar to what was done for Excel, with two members -- DisplayName and ProgrammaticName, for which CE can use to provide an uniform display. The IHostApplication can then do whatever they need to do to provide that 2 information. For other unknown IHostApplication, it's probably best that CE simply display the name as known to the VBComponent.

The above is actually not germane to the original issue -- renaming a document module. We are not doing anything special in this case:

                case ComponentType.Document:
                    {
                        using (var properties = component.Properties)
                        using (var property = properties["_CodeName"])
                        {
                            property.Value = model.NewName;
                        }
                        break;
                    }

The property _CodeName doesn't exist on Access nor on PPT. Word has it but it seems to behave strangely (doesn't work first time but does on 2nd time). To properly rename those documents, Host OM might be necessary.

SmileyFtW commented 5 years ago

While I was stumbling around working on the project and learning about the PPT model I wrote this to change the name:

Private Sub RenameSlide1()
    Dim currPresentation As PowerPoint.Presentation
    Set currPresentation = Application.Presentations(1)
    With currPresentation
        Debug.Print .Slides(1).Name
        .Slides(1).Name = "PracticeMemberCardSlide"
    End With
End Sub