Office COM Add-In code


/ Published in: VB.NET
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. '_______________________________________________________________________
  2.  
  3. 'Hello,
  4.  
  5. 'I followed the "tutorial" / article poste on the msdn.microsoft.com
  6. 'site located at this link
  7. '<url>http://msdn.microsoft.com/library/default.asp?url=/library/en-'us/dnofftalk/html/office03072002.asp</url>
  8.  
  9. 'But it does not compile. It gives an error for the declaration of
  10. 'Imports PowerPoint.PpSlideLayout
  11. 'Dim objPresentation As PowerPoint.Presentation
  12.  
  13. 'and it does not recognize ppLayoutBlank. Has anyone else followed
  14. 'through this article to test out the code? I am new to VB .NET and the
  15. 'development of Office Add-Ins. I've posted my code below.
  16.  
  17. '_______________________________________________________________________
  18.  
  19. Imports Microsoft.Office.Core
  20. imports Extensibility
  21. Imports System.Runtime.InteropServices
  22. ' *** BEGIN CUSTOM CODE ***
  23. Imports Microsoft.Office.Core.MsoControlType
  24. Imports Microsoft.Office.Core.MsoButtonStyle
  25. Imports Microsoft.Office.Core.MsoFileDialogType
  26. Imports Microsoft.Office.Core.MsoFileDialogView
  27. Imports PowerPoint.PpSlideLayout
  28. Imports Microsoft.Office.Core.MsoTriState
  29. ' *** END CUSTOM CODE ***
  30.  
  31. #Region " Read me for Add-in installation and setup information. "
  32. ' When run, the Add-in wizard prepared the registry for the Add-in.
  33. ' At a later time, if the Add-in becomes unavailable for reasons such
  34. as:
  35. ' 1) You moved this project to a computer other than which is was
  36. originally created on.
  37. ' 2) You chose 'Yes' when presented with a message asking if you wish
  38. to remove the Add-in.
  39. ' 3) Registry corruption.
  40. ' you will need to re-register the Add-in by building the
  41. PowerPointAddInSetup project
  42. ' by right clicking the project in the Solution Explorer, then choosing
  43. install.
  44. #End Region
  45.  
  46. <GuidAttribute("B3BEDDA6-95EE-49A5-8AD7-4C2200A5F9C2"),
  47. ProgIdAttribute("PowerPointAddIn.Connect")> _
  48. Public Class Connect
  49.  
  50. Implements Extensibility.IDTExtensibility2
  51.  
  52. Dim applicationObject as Object
  53. Dim addInInstance As Object
  54. ' *** BEGIN CUSTOM CODE
  55. Dim WithEvents objCommandBarButton As CommandBarButton
  56. ' *** END CUSTOM CODE
  57.  
  58. Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
  59. Extensibility.IDTExtensibility2.OnBeginShutdown
  60. ' *** BEGIN CUSTOM CODE
  61. objCommandBarButton.Delete()
  62. ' *** END CUSTOM CODE
  63. End Sub
  64.  
  65. Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
  66. Extensibility.IDTExtensibility2.OnAddInsUpdate
  67. ' *** BEGIN CUSTOM CODE
  68. ' No code needed in this method
  69. ' *** END CUSTOM CODE
  70. End Sub
  71.  
  72. Public Sub OnStartupComplete(ByRef custom As System.Array)
  73. Implements Extensibility.IDTExtensibility2.OnStartupComplete
  74. ' *** BEGIN CUSTOM CODE
  75. Dim objCommandBars As CommandBars
  76. Dim objcommandBar As CommandBar
  77. Dim objCommandBarControl As CommandBarControl
  78.  
  79. ' Create a menu command on the "Tools" menu.
  80. objCommandBars = applicationObject.CommandBars
  81. objcommandBar = objCommandBars.Item("Tools")
  82.  
  83. 'Make sure menu command doesn't already exist.
  84. For Each objCommandBarControl In objcommandBar.Controls
  85. If objCommandBarControl.Caption = "Slides from Graphics..."
  86. Then
  87. objcommandBar.Controls.Item("Slides from
  88. Graphics...").Delete()
  89. End If
  90. Next objCommandBarControl
  91.  
  92. objCommandBarButton =
  93. objcommandBar.Controls.Add(msoControlButton)
  94.  
  95. With objCommandBarButton
  96. .Caption = "New Slides from Graphics..."
  97. .Style = msoButtonCaption
  98. .Tag = "Slides from Graphics..."
  99. .OnAction = "!<PoserPointAddIn.Connect>"
  100. .Visible = True
  101. End With
  102. ' *** END CUSTOM CODE
  103. End Sub
  104.  
  105. Public Sub OnDisconnection(ByVal RemoveMode As
  106. Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
  107. Implements Extensibility.IDTExtensibility2.OnDisconnection
  108. ' *** BEGIN CUSTOM CODE
  109. On Error Resume Next
  110.  
  111. 'Disconnect the shared add-in, no matter how the host
  112. application was shut down.
  113. If RemoveMode <>
  114. Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then
  115. Call OnBeginShutdown(custom)
  116. End If
  117.  
  118. applicationObject = Nothing
  119. ' *** END CUSTOM CODE
  120. End Sub
  121.  
  122. Public Sub OnConnection(ByVal application As Object, ByVal
  123. connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As
  124. Object, ByRef custom As System.Array) Implements
  125. Extensibility.IDTExtensibility2.OnConnection
  126. applicationObject = application
  127. addInInstance = addInInst
  128.  
  129. ' *** BEGIN CUSTOM CODE
  130. 'No matter how the host application started, connect the shared
  131. add-in.
  132. If (connectMode <>
  133. Extensibility.ext_ConnectMode.ext_cm_Startup) Then
  134. Call OnStartupComplete(custom)
  135. End If
  136. ' *** END CUSTOM CODE
  137. End Sub
  138.  
  139. ' *** BEGIN CUSTOM CODE ***
  140. Private Sub objCommandBarButton_Click(ByVal Ctrl As
  141. CommandBarButton, ByRef CancelDefault As Boolean) Handles
  142. objCommandBarButton.Click
  143. ' Create an open file dialog box to transmit
  144. ' the user's selected file choices.
  145. Dim objOpenFileDialog As FileDialog =
  146. applicationObject.FileDialog(msoFileDialogOpen)
  147. Dim objSelectedItem As Object
  148. Dim objPresentation As PowerPoint.Presentation
  149.  
  150. With objOpenFileDialog
  151. .AllowMultiSelect = True
  152. .Title = "Select Graphics Files"
  153. 'Clear any previous filters. Allow only bitmap, GIF, and
  154. JPEG files to be selected.
  155. .Filters.Clear()
  156. .Filters.Add("Selected Graphics Files",
  157. "*.bmp;*.gif;*.jpg")
  158. .InitialView = msoFileDialogViewThumbnail
  159.  
  160. ' "-1" means the user clicked the Open button.
  161. If .Show = -1 Then
  162. objPresentation = applicationObject.Presentations.Add
  163. For Each objSelectedItem In .SelectedItems
  164. ' Add one slide per selected graphics file.
  165. objPresentation.SlidesAdd(1,
  166. ppLayoutBlank).Shapes.AddPicture(objSelectedItem, msoFalse, msoTrue, 0,
  167. 0)
  168. Next objSelectedItem
  169. End If
  170. End With
  171. End Sub
  172. ' *** END CUSTOM CODE ***
  173.  
  174. End Class

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.