Return to Snippet

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


Initial Code
'_______________________________________________________________________

'Hello,

'I followed the "tutorial" / article poste on the msdn.microsoft.com
'site located at this link
'<url>http://msdn.microsoft.com/library/default.asp?url=/library/en-'us/dnofftalk/html/office03072002.asp</url>

'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
' *** BEGIN CUSTOM CODE ***
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
' *** END CUSTOM CODE ***

#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
as:
'   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
install.
#End Region

<GuidAttribute("B3BEDDA6-95EE-49A5-8AD7-4C2200A5F9C2"),
ProgIdAttribute("PowerPointAddIn.Connect")> _
Public Class Connect

	Implements Extensibility.IDTExtensibility2

	Dim applicationObject as Object
    Dim addInInstance As Object
    ' *** BEGIN CUSTOM CODE
    Dim WithEvents objCommandBarButton As CommandBarButton
    ' *** END CUSTOM CODE

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

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
        ' *** 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..."
Then
                objcommandBar.Controls.Item("Slides from
Graphics...").Delete()
            End If
        Next objCommandBarControl

        objCommandBarButton =
objcommandBar.Controls.Add(msoControlButton)

        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
Extensibility.IDTExtensibility2.OnConnection
        applicationObject = application
        addInInstance = addInInst

        ' *** BEGIN CUSTOM CODE
        'No matter how the host application started, connect the shared
add-in.
        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
objCommandBarButton.Click
        ' Create an open file dialog box to transmit
        ' the user's selected file choices.
        Dim objOpenFileDialog As FileDialog =
applicationObject.FileDialog(msoFileDialogOpen)
        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.Clear()
            .Filters.Add("Selected Graphics Files",
"*.bmp;*.gif;*.jpg")
            .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.
                    objPresentation.SlidesAdd(1,
ppLayoutBlank).Shapes.AddPicture(objSelectedItem, msoFalse, msoTrue, 0,
0)
                Next objSelectedItem
            End If
        End With
    End Sub
    ' *** END CUSTOM CODE ***

End Class

Initial URL
http://markmail.org/message/kjaj7du7pxj4tilr

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

Initial Title
Office COM Add-In code

Initial Tags


Initial Language
VB.NET