Hi all -
I am having troubles with implementing a CommandBar in Microsoft Word
utilizing VB.net. My CommandBar appears when I start Word, but if I open an
existing document, it does not appear. My best guess is that ActiveDocument
isn't getting set correctly, but I really don't know how else to implement
this. I am attaching an external template to avoid making any changes to
Normal.dot, but my code generates the CommandBar. I have included a snip of
OnStartupComple te and OnConnection below for your inspection.
Any help with this would be *very* appreciated. My deadline is in a couple
of hours and I just discovered this little "feature" a couple of days ago
and haven't been able to resolve it.
Thanks!
Josh
Imports Office.MsoContr olType
Imports Office.MsoButto nStyle
Imports Office.MsoTriSt ate
Imports Office
Imports Word
Friend WithEvents ThisDocument As Word.Document
Friend WithEvents ThisApplication As Word.Applicatio n
Public Class Connect
Implements Extensibility.I DTExtensibility 2
Dim applicationObje ct as Object
dim addInInstance as object
............... ........
Public Sub OnStartupComple te(ByRef custom As System.Array) Implements
Extensibility.I DTExtensibility 2.OnStartupComp lete
******* FAILS HERE *****
ThisDocument = applicationObje ct.ActiveDocume nt
******* FAILS HERE *****
Dim myTemplate As Template
ThisDocument.At tachedTemplate = "C:\TempWor d Add-In\BCC.dot"
myTemplate = ThisDocument.At tachedTemplate
MsgBox(myTempla te.Path & applicationObje ct.PathSeparato r _
& myTemplate.Name )
.......
Public Sub OnConnection(By Val application As Object, ByVal connectMode
As Extensibility.e xt_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.I DTExtensibility 2.OnConnection
ThisApplication = application
applicationObje ct = application
addInInstance = addInInst
If (connectMode <> Extensibility.e xt_ConnectMode. ext_cm_Startup)
Then _
Call OnStartupComple te(custom)
End Sub