J
Josh Asbury
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
OnStartupComplete and OnConnection below for your inspection.
I have put the some debug code into my
OnStartupComplete. When I start Word, the first MsgBox fires with "Document
1" in it. However, when I launch an existing document by double-clicking it
within Explorer, the else condition is called and the "No documents are
open" dialog fires. I'm clueless here. Is there a way that I can call
something like Documents.Add ( or something ) from within the else block and
activate the document from there?
Thanks!
Josh
Imports Office.MsoControlType
Imports Office.MsoButtonStyle
Imports Office.MsoTriState
Imports Office
Imports Word
Friend WithEvents ThisDocument As Word.Document
Friend WithEvents ThisApplication As Word.Application
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject as Object
dim addInInstance as object
.......................
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
If applicationObject.Documents.Count >= 1 Then
MsgBox(applicationObject.ActiveDocument.Name)
Else
MsgBox("No documents are open")
End If
******* FAILS HERE *****
ThisDocument = applicationObject.ActiveDocument
******* FAILS HERE *****
Dim myTemplate As Template
ThisDocument.AttachedTemplate = "C:\TempWord Add-In\BCC.dot"
myTemplate = ThisDocument.AttachedTemplate
MsgBox(myTemplate.Path & applicationObject.PathSeparator _
& myTemplate.Name)
.......
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
ThisApplication = application
applicationObject = application
addInInstance = addInInst
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)
End Sub
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
OnStartupComplete and OnConnection below for your inspection.
I have put the some debug code into my
OnStartupComplete. When I start Word, the first MsgBox fires with "Document
1" in it. However, when I launch an existing document by double-clicking it
within Explorer, the else condition is called and the "No documents are
open" dialog fires. I'm clueless here. Is there a way that I can call
something like Documents.Add ( or something ) from within the else block and
activate the document from there?
Thanks!
Josh
Imports Office.MsoControlType
Imports Office.MsoButtonStyle
Imports Office.MsoTriState
Imports Office
Imports Word
Friend WithEvents ThisDocument As Word.Document
Friend WithEvents ThisApplication As Word.Application
Public Class Connect
Implements Extensibility.IDTExtensibility2
Dim applicationObject as Object
dim addInInstance as object
.......................
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
If applicationObject.Documents.Count >= 1 Then
MsgBox(applicationObject.ActiveDocument.Name)
Else
MsgBox("No documents are open")
End If
******* FAILS HERE *****
ThisDocument = applicationObject.ActiveDocument
******* FAILS HERE *****
Dim myTemplate As Template
ThisDocument.AttachedTemplate = "C:\TempWord Add-In\BCC.dot"
myTemplate = ThisDocument.AttachedTemplate
MsgBox(myTemplate.Path & applicationObject.PathSeparator _
& myTemplate.Name)
.......
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
ThisApplication = application
applicationObject = application
addInInstance = addInInst
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)
End Sub