ActiveDocument Not Getting Set

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.

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.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

******* 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
 
J

Josh Asbury

So, here's the latest: I have put the following 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?

Help!!!! SOS!!!

Thanks!
Josh


If applicationObject.Documents.Count >= 1 Then
MsgBox(applicationObject.ActiveDocument.Name)
Else
MsgBox("No documents are open")
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top