English 中文(简体)
Is there a future for PowerPoint VBA/VSTO? [closed]
原标题:
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Does anyone know what the future holds for VBA/VSTO programming in PowerPoint? I ve been working on a Office automation project and find it frustrating to work with PowerPoint in particular since it seems to be one level below VBA support found in Excel or Word.

It feels like MS is trying to phase out support for VBA in PowerPointsince they dropped macro recording in version 2007 and the object model lacks some key features support.

最佳回答

I m not sure if this is the answer you want to hear, but development in PowerPoint with VBA is actually good. I do quite a bit of it (as well as Word and Excel) and it is robust enough. The PowerPoint OM that can be programmed against with VBA is updated with each of the new versions of PPT. In PPT 2007, you can create Custom XML against any object on a slide - far more powerful than options available in Excel and Word. In contrast, Word 2007 has Content Controls, which, in order for PPT to be some kind Crystal Reports light-weight replacement, it would benefit from. In PPT 2010 (beta), you can programmatically create SmartArt, for example, as you can with Word/Excel 2010. You can also programmatically work with media elements better than before. VSTO, from an OM perspective, doesn t offer a whole lot more than VBA though.

It may just depend on your needs though - do you create standard bullet slides? Do you do extended animation? Do you do reporting? Are you creating eLearning "apps"? If you have specific questions on the OM, we can try to help you here (but maybe the feature just doesn t exist).

Agreed that removing the macro recorder kind of sucked, that was a useful feature. Directly working with the PML/DML is also a pain. There are things that I wish the OM did support as well. But in concurrence with caving, I don t believe VBA is going away any time soon.


NOTE: THIS DOES NOT WORK. IT IS PROVIDED ONLY AS A STARTING POINT IF FOLKS WANT TO TRY TO DEVELOP THIS INTO SOMETHING THAT MAY WORK (if you can get it to work, please feel free to edit this post).

  1. Create a class called "clsPPTEvents"
  2. Paste in the following code.

    Public WithEvents PPTEvent As Application
    Private Declare Function GetCursorPos Lib "user32" (ByVal lpPoint As POINTAPI) As Long
    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Dim ret As Long
    Dim mousePosition As POINTAPI
    Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
        Dim ElementID As Long
        Dim Arg1 As Long
        Dim Arg2 As Long
        With Sel
            If .Type = ppSelectionShapes Then
                Dim sr As ShapeRange
                sr = .ShapeRange
                If sr.Type = msoChart Then
                    Dim sh As Shape
                    Dim slideNumber As Integer
                    slideNumber = ActiveWindow.View.Slide.SlideIndex
                    sh = ActivePresentation.Slides(slideNumber).Shapes(sr.Name)
                    Dim crt As Chart
                    crt = sh.Chart
                    H = ActiveWindow.Height
                    w = ActiveWindow.Width
                    ret = GetCursorPos(mousePosition)
                    x = mousePosition.x
                    y = mousePosition.y
                    crt.GetChartElement(x, y, ElementID, Arg1, Arg2)
                    MsgBox("X: " & x & ", Y: " & y & vbNewLine & _
                    "ElementID: " & ElementID & ", Arg1: " & Arg1 & ", Arg2: " & Arg2)
                End If
            End If
        End With
    End Sub
    
  3. In a regular module, you can start/stop the event handling with this:

    Public newPPTEvents As New clsPPTEvents
    Sub StartEvents()
        Set newPPTEvents.PPTEvent = Application
    End Sub
    Sub EndEvents()
        Set newPPTEvents.PPTEvent = Nothing
    End Sub
    

Note that in the code in #2, it doesn t work because of what GetCursorPos returns, which is the screen X, Y. In looking at event, it appears that what the GetChartElement wants is either the Window or Pane bounding box s coordinates or just the chart s itself.

问题回答

Powerpoint has never been a popular platform for VBA development. I can understand dropping UI features for VBA in that context. Tt is very easy to include VBA support for Powerpoint on the strength of Excel and Word - which will not go away soon, if at all. My money will be on legacy support in the long term, with poor to nonexistent assistance from Microsoft for problems.

Remember that MS is all about backward compatibility - and they are very careful when they drop it.

I agree PPT is well below other vba. Above all it seems buggy see Weird bug on powerpoint vba

Model event is awkward like no auto execution How to automatically trigger the App Object initialization in Powerpoint?

auto_open is possible only in circumvoluted way by creating an addin what about users who receives your ppt and don t know how to install the plugin :(

See this article for summarizing why VSTO is the way to go. Compares with VBA for Excel, but same thing applies for Powerpoint too.





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签