Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Addin for word and Excel

Status
Not open for further replies.

cyrus71

Programmer
Feb 6, 2006
34
SE
Hi,

I have built a Shared Add-in for word and Excel, it worked good for both of them, but I dont know what I did when i played with word, now it stopped working on Word and it just works on Excel.

What it depends on, I don't remember what i did but i played with toolbar and its customize and option.
 
nope - sorry - telepathy mode isn't turned on. How on earth do you expect someone to diagnose an isse with an add-in, based on "What it depends on, I don't remember what i did but i played with toolbar and its customize and option."

The quality of answer is directly proportional to the quality of question. You will need to give far more information than that and include any relevant code, how you set up the add-in, how you configured it within Excel and Word, where it is saved and what it does.



Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Actualy no Add-in works for Word anymore,
 
How are we going to know why it works for Excel and not for Word when you havn't given us the faintest ideas of what the add-in does ???

The basic and most probable answer is that Word VBA is not the same as Excel VBA - they have different object models, properties and methods so I would be very surprised if you could write something that would be applicable to both Word & Excel at the same time without running different code depending on the app

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
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?
 
Really don't know - looks like you are writing in C# so you may be better off asking in that forum. Only thing I can think of is if you need to get your code "trusted" or that by messing with the toolbar, you have changed its configuration. In excel, the toolbar file is *.xlb - find and remove that - not sure what the file is in Word but as a starter it may well be a good idea to find the toolbar file and delete it so that the toolbar gets set back to default

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
i want to debugg my code by adding breakpoints, but VS doesnot answer to breakpoints neither, it is something about webguarden or entire shadow copy cache,

but solution ? i dont know
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top