Return to Snippet

Revision: 22894
at January 25, 2010 14:05 by shaamil

Initial Code


'I followed the "tutorial" / article poste on the
'site located at this link

'But it does not compile. It gives an error for the declaration of
'Imports PowerPoint.PpSlideLayout
'Dim objPresentation As PowerPoint.Presentation

'and it does not recognize ppLayoutBlank. Has anyone else followed
'through this article to test out the code? I am new to VB .NET and the
'development of Office Add-Ins. I've posted my code below.


Imports Microsoft.Office.Core
imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core.MsoControlType
Imports Microsoft.Office.Core.MsoButtonStyle
Imports Microsoft.Office.Core.MsoFileDialogType
Imports Microsoft.Office.Core.MsoFileDialogView
Imports PowerPoint.PpSlideLayout
Imports Microsoft.Office.Core.MsoTriState

#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such
'   1) You moved this project to a computer other than which is was
originally created on.
'   2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
'   3) Registry corruption.
' you will need to re-register the Add-in by building the
PowerPointAddInSetup project
' by right clicking the project in the Solution Explorer, then choosing
#End Region

ProgIdAttribute("PowerPointAddIn.Connect")> _
Public Class Connect

	Implements Extensibility.IDTExtensibility2

	Dim applicationObject as Object
    Dim addInInstance As Object
    Dim WithEvents objCommandBarButton As CommandBarButton

    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
        ' *** BEGIN CUSTOM CODE
        ' *** END CUSTOM CODE
    End Sub

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
        ' *** BEGIN CUSTOM CODE
        ' No code needed in this method
        ' *** END CUSTOM CODE
    End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
        ' *** BEGIN CUSTOM CODE
        Dim objCommandBars As CommandBars
        Dim objcommandBar As CommandBar
        Dim objCommandBarControl As CommandBarControl

        ' Create a menu command on the "Tools" menu.
        objCommandBars = applicationObject.CommandBars
        objcommandBar = objCommandBars.Item("Tools")

        'Make sure menu command doesn't already exist.
        For Each objCommandBarControl In objcommandBar.Controls
            If objCommandBarControl.Caption = "Slides from Graphics..."
                objcommandBar.Controls.Item("Slides from
            End If
        Next objCommandBarControl

        objCommandBarButton =

        With objCommandBarButton
            .Caption = "New Slides from Graphics..."
            .Style = msoButtonCaption
            .Tag = "Slides from Graphics..."
            .OnAction = "!<PoserPointAddIn.Connect>"
            .Visible = True
        End With
        ' *** END CUSTOM CODE
    End Sub

    Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
        ' *** BEGIN CUSTOM CODE
        On Error Resume Next

        'Disconnect the shared add-in, no matter how the host
application was shut down.
        If RemoveMode <>
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then
            Call OnBeginShutdown(custom)
        End If

        applicationObject = Nothing
        ' *** END CUSTOM CODE
    End Sub

    Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
Object, ByRef custom As System.Array) Implements
        applicationObject = application
        addInInstance = addInInst

        ' *** BEGIN CUSTOM CODE
        'No matter how the host application started, connect the shared
        If (connectMode <>
Extensibility.ext_ConnectMode.ext_cm_Startup) Then
            Call OnStartupComplete(custom)
        End If
        ' *** END CUSTOM CODE
    End Sub

    ' *** BEGIN CUSTOM CODE ***
    Private Sub objCommandBarButton_Click(ByVal Ctrl As
CommandBarButton, ByRef CancelDefault As Boolean) Handles
        ' Create an open file dialog box to transmit
        ' the user's selected file choices.
        Dim objOpenFileDialog As FileDialog =
        Dim objSelectedItem As Object
        Dim objPresentation As PowerPoint.Presentation

        With objOpenFileDialog
            .AllowMultiSelect = True
            .Title = "Select Graphics Files"
            'Clear any previous filters. Allow only bitmap, GIF, and
JPEG files to be selected.
            .Filters.Add("Selected Graphics Files",
            .InitialView = msoFileDialogViewThumbnail

            ' "-1" means the user clicked the Open button.
            If .Show = -1 Then
                objPresentation = applicationObject.Presentations.Add
                For Each objSelectedItem In .SelectedItems
                    ' Add one slide per selected graphics file.
ppLayoutBlank).Shapes.AddPicture(objSelectedItem, msoFalse, msoTrue, 0,
                Next objSelectedItem
            End If
        End With
    End Sub
    ' *** END CUSTOM CODE ***

End Class

Initial URL

Initial Description
not tested.. but saved it for later. :)

Initial Title
Office COM Add-In code

Initial Tags

Initial Language