Newbie question: Form called by add-in doesn't have access to application

B

Bernhard

Hi

I'm trying to write an add-in for Office XP. The add-in inserts a menu item
into the tools menu, when I click on it the procedure

Public Sub mmCommand_Click() Handles mmCommand.Click

is called. From here I have access to the application object which I got
from the procedure 'Public Sub OnConnection'. Here I can access e.g. the
properties of the currently opened document.

In the mmCommand_Click procedure I call a form 'ExportProperty':
Dim dlgExport As New ExportProperty()
dlgExport.ShowDialog()

The form is displayed but I don't have access to the application object
anymore. I have spent almost a day now but I'm lost how to do this. Any help
is appreciated :)

Regards, Bernhard
 
C

Chris, Master of All Things Insignificant

I think I know what will correct your problem

You need to define a global class variable (define it outside of any
sub/function but inside the class)
Dim ApplicationObject As Microsoft.Office.Interop.Outlook.Application

Then your OnConnection will look like this:
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

ApplicationObject = DirectCast(application,
Microsoft.Office.Interop.Outlook.Application)

End Sub

This way you always have access to the application no matter where you are
in your class.

Hope this helps
Chris
 
B

Bernhard

Hmm,
this is how my code already looked like, doesn't seem to work yet. Maybe
it's a 'class thing' (I'm not very firm about OOP yet...)?
The addin starter code is included in a class 'Public Class Connect', the
new form is created by VB .NET as another class 'Public Class
ExportProperty' so in the form I'm actually in another class. Does this give
a clue?
Bernhard
 
B

Bernhard

I kept trying and found something that works.

First the global class variable in class 'Connect':
Public ApplicationObject As New
Microsoft.Office.Interop.Outlook.Application()

Then, in the form that is called:
Dim y As New Connect()

Now I have access to the application object in the form as well.


It seems to work but it seems a bit dirty to me..., is this a good solution
or are there any better ideas?

Thanks for your help :)
Bernhard
 

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