Reputation: 85
I am creating a MS Word VSTO. In VSTO I have added a custom task pane that display my User control at right side of MS Word. Here is the code snippet to add Custom Task Pane.
Public WithEvents _taskPane As Microsoft.Office.Tools.CustomTaskPane
Private myTaskPaneCollection As Microsoft.Office.Tools.CustomTaskPaneCollection
myTaskPaneCollection = Globals.Factory.CreateCustomTaskPaneCollection _
(Nothing, Nothing, "CustomTaskPanes", "CustomTaskPanes", Me)
_taskPane = myTaskPaneCollection.Add(dvPanel, My.Resources.dvTaskPane)
_taskPane.Control.Dock = Windows.Forms.DockStyle.Left
_taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight
_taskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal
_taskPane.Width = 300
_taskPane.Visible = True
Note : DVPANEL is my usercontrol that will display matadata about opened Document.
I have written this code at Application.DocumentOpen() function as I want to display task pane only when any document is opened. It work fine when i run it from MS Visual Studio. But when I opened any Document from my application. It fails. Here is the snapshot of actual error.
I have searched a lot but could not get more information. Here is a link that i have refereed. http://social.msdn.microsoft.com/forums/vstudio/en-US/205cdc8b-3b20-4cb8-ad30-c6177e9f8435/argument-null-reference-exception-project-addin
Thanks in advance. Waiting for favorable response.
Upvotes: 1
Views: 531
Reputation: 688
try this
Imports Microsoft.Office.Core Public Class TaskPanes Private _panes As Microsoft.Office.Tools.CustomTaskPaneCollection Public Sub AddTaskPane(ByVal cntl As System.Windows.Forms.UserControl, ByVal paneName As String) _panes = Globals.ThisAddIn.CustomTaskPanes Dim pane As Microsoft.Office.Tools.CustomTaskPane = _panes.Add(cntl, paneName) pane.Control.Dock = Windows.Forms.DockStyle.Left pane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight pane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal pane.Width = 300 pane.Visible = True End Sub End Class
Upvotes: 1