Thanks again,
It worked before for both, now ms word dont answer to any Shared Add-in i build.
here is a little bit of my code: I write the methods that i made myself and those i changed, other methods are exact same when you create a shared add-in.
namespace MyAddin1
{
using System;
using System.Reflection;
using System.Windows.Forms;
using Extensibility;
using System.Runtime.InteropServices;
using Microsoft.Office.Core;
using EnvDTE;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
[GuidAttribute("51C0A1CD-5ABA-408C-91BD-A085D8416417"), ProgId("MyAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
Word.Application wordApp = null;
Excel.Application excelApp = null;
Microsoft.Office.Core.CommandBarButton insertText;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
SetApplicationFields(application);
Microsoft.Office.Core.CommandBar toolBar = null;
if (wordApp != null)
{
toolBar = AddWordToolbar(wordApp, "Ignito Toolbar");
}
if (excelApp != null)
{
toolBar = AddExcelToolbar(excelApp, "Ignito Toolbar");
}
// Create a button to add text.
insertText = MakeANewButton(toolBar, "Insert text", 1044, new _CommandBarButtonEvents_ClickEventHandler(insertText_Click));
}
private void SetApplicationFields(object application)
{
if (application is Word.Application)
{
wordApp = (Word.Application)application;
excelApp = null;
}
else if (application is Excel.Application)
{
excelApp = (Excel.Application)application;
wordApp = null;
}
}
private CommandBar AddWordToolbar(Word.Application word, string toolbarName)
{
CommandBar toolBar = null;
try
{
// Create a command bar for the add-in
object missing = System.Reflection.Missing.Value;
toolBar = (CommandBar)wordApp.CommandBars.Add(toolbarName, MsoBarPosition.msoBarTop, missing, true);
toolBar.Visible = true;
return toolBar;
}
catch
{
return null;
}
}
private CommandBar AddExcelToolbar(Excel.Application excel, string toolbarName)
{
Microsoft.Office.Core.CommandBar toolBar = null;
try
{
// Create a command bar for the add-in
object missing = System.Reflection.Missing.Value;
toolBar = (CommandBar)excelApp.CommandBars.Add(toolbarName, MsoBarPosition.msoBarTop, missing, true);
toolBar.Visible = true;
return toolBar;
}
catch
{
return null;
}
}
private CommandBarButton MakeANewButton(CommandBar commandBar, string caption, int faceID, _CommandBarButtonEvents_ClickEventHandler clickHandler)
{
object missing = System.Reflection.Missing.Value;
try
{
Microsoft.Office.Core.CommandBarButton newButton;
newButton = (CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, missing, missing, missing, missing);
newButton.Caption = caption;
newButton.FaceId = faceID;
newButton.Click += clickHandler;
return newButton;
}
catch
{
return null;
}
}
public void insertText_Click(CommandBarButton barButton, ref bool someBool)
{
if (wordApp != null)
{
this.wordApp.ActiveWindow.Selection.InsertBefore("someText");
}
else if (excelApp != null)
{
this.excelApp.ActiveCell.Value2 = "someText";
}
}
}
}
thanks again for your helping,
another question, wheni it worked for word the last method inserted "someText" to the document but it don't insert "someText" to activeCell, why?