Exception when adding a toolbar as a word-addin

M

Matthias Langbein

Hi all,

I tried to build a MSDN-Tip how to integrates a word-toolbar in a
addin:
(http://support.microsoft.com/Default.aspx?kbid=302901#XSLTH3228121124120121120120)

The class member applicationObject was initialized with the
word-application-objekt. When calling


Microsoft.Office.Core.Commandbar toolbar = null;
try
{
toolbar = (Microsoft.Office.Core.CommandBar)_
applicationObject.CommandBars.Add("My Toolbar",_
Microsoft.Office.Core.MsoBarPosition.msoBarFloating,_
System.Reflection.Missing.Value, true);
}
catch (Exception ee)
{
......
}


I recieve the exception:
"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."
which means pretty much:
"The bject link was not assigned with a object instance."

How comes? I'm desparate...
THX for all the help, yours Langi
 
B

Bob Butler

Matthias Langbein said:
Hi all,

I tried to build a MSDN-Tip how to integrates a word-toolbar in a
addin:
(http://support.microsoft.com/Default.aspx?kbid=302901#XSLTH3228121124120121
120120)

The class member applicationObject was initialized with the
word-application-objekt. When calling


Microsoft.Office.Core.Commandbar toolbar = null;
try
{
toolbar = (Microsoft.Office.Core.CommandBar)_
applicationObject.CommandBars.Add("My Toolbar",_
Microsoft.Office.Core.MsoBarPosition.msoBarFloating,_
System.Reflection.Missing.Value, true);
}
catch (Exception ee)
{
.....
}


I recieve the exception:
"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt."
which means pretty much:
"The bject link was not assigned with a object instance."

How comes? I'm desparate...
THX for all the help, yours Langi

You are writing an add-in using C# and posted the question to a COM group
and 2 VB groups?

Try searching for newsgroups containing .dotnet. in the name.
 
A

Alex

Bob Butler said:
You are writing an add-in using C# and posted the question to a COM group and 2 VB groups?

Try searching for newsgroups containing .dotnet. in the name.

microsoft.public.office.developer.com.add_ins is the correct group.
Followup-To set accordingly.
 
B

Bob Butler

Jamie Ayer said:
On his behalf, writing an office plug in with C# is creating a COM
addin...

I considered that but any issues are still more likely to be C#/dotnet
related than direclty COM related. BTW, changing the subject is not usually
a good idea because it causes some newsreaders to see it as a new thread.
 
M

Matthias Langbein

Hi all,
I decided to post the code, maybe someone can tell me why there is the
exception...





namespace MyOwnAddIn
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;

[GuidAttribute("715D48EE-9F94-4055-AC62-4D22E89913AD"),
ProgId("MyOwnAddIn.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2
{
public Connect()
{
}

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
if (application is Word.Application)
{ wordApp = (Word.Application)application; }
Microsoft.Office.Core.CommandBar toolBar = null;
if (wordApp != null)
{ toolBar = AddWordToolbar(wordApp, "Some useful toolbar."); }
}

public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
}

public void OnAddInsUpdate(ref System.Array custom)
{
}

public void OnStartupComplete(ref System.Array custom)
{
}

public void OnBeginShutdown(ref System.Array custom)
{
}

private Microsoft.Office.Core.CommandBar
AddWordToolbar(Word.Application word, string toolbarName)
{
Microsoft.Office.Core.CommandBar toolBar = null;
try
{
object missing = System.Reflection.Missing.Value;
toolBar = (Microsoft.Office.Core.CommandBar)
wordApp.CommandBars.Add(toolbarName,
Microsoft.Office.Core.MsoBarPosition.msoBarTop,
missing, true );
toolBar.Visible = true;
return toolBar;
}
catch (Exception ee)
{
System.Windows.Forms.MessageBox.Show(ee.Message);
return null;
}
}

private object applicationObject;
private object addInInstance;
private Word.Application wordApp = null;
}
}
 
M

Matthias Langbein

I get the warning:

'Microsoft.Office.Core.CommandBar' is defined in multiple places;
using definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\office.dll'

Might this have anything to do with it? And how do I solve this
problem?
 
B

- B@rney

Yes, it has something to do with that error message.

I had the same problem. The resolution was to correct my reference to point
to the office.dll in the GAC and make sure I didn't have references to any
other versions of the office.dll

HTH

--
- B@rney
___________________________
http://www.sharepointdemo.biz/
http://www.sharepointdemo.biz/blogs/bjarne/


Matthias Langbein said:
I get the warning:

'Microsoft.Office.Core.CommandBar' is defined in multiple places;
using definition from
'c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\office.dll'

Might this have anything to do with it? And how do I solve this
problem?


Hi all,
I decided to post the code, maybe someone can tell me why there is the
exception...





namespace MyOwnAddIn
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;

[GuidAttribute("715D48EE-9F94-4055-AC62-4D22E89913AD"),
ProgId("MyOwnAddIn.Connect")]

public class Connect : Object, Extensibility.IDTExtensibility2
{
public Connect()
{
}

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
if (application is Word.Application)
{ wordApp = (Word.Application)application; }
Microsoft.Office.Core.CommandBar toolBar = null;
if (wordApp != null)
{ toolBar = AddWordToolbar(wordApp, "Some useful toolbar."); }
}

public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
}

public void OnAddInsUpdate(ref System.Array custom)
{
}

public void OnStartupComplete(ref System.Array custom)
{
}

public void OnBeginShutdown(ref System.Array custom)
{
}

private Microsoft.Office.Core.CommandBar
AddWordToolbar(Word.Application word, string toolbarName)
{
Microsoft.Office.Core.CommandBar toolBar = null;
try
{
object missing = System.Reflection.Missing.Value;
toolBar = (Microsoft.Office.Core.CommandBar)
wordApp.CommandBars.Add(toolbarName,
Microsoft.Office.Core.MsoBarPosition.msoBarTop,
missing, true );
toolBar.Visible = true;
return toolBar;
}
catch (Exception ee)
{
System.Windows.Forms.MessageBox.Show(ee.Message);
return null;
}
}

private object applicationObject;
private object addInInstance;
private Word.Application wordApp = null;
}
}
 

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

Similar Threads


Top