M
Medes
Hi everybody,
I have created an Add-in for MS Word. It is a toolbar that contains a button
when you click on button it loads a Form.
My version of office is 2003,
It works well, but with a few problems. if you assume that we have 4 cases
it works at two of them. here is the 4 cases:
1.if you double click on a .doc file to open it, everything goes well (my
button works).
2.if you open a new instance of Word, and use the document as a new document
everything goes well here too.
3. if you have already opened a new instance of word and go to file -> open
(as usual when you open an exsiting .doc file) it does not work, my button
does not opens the form.
4.if you have uploaded a .doc file to Shared Documents on a Sharepoint Site
and want to open it, my Add-in does not work.
here is a bit of my code:
[GuidAttribute("79CC5244-EADC-4F4B-ACF1-9387460BEDF4"),
ProgId("IgnitoAddIn.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
//-------
my variables
//-------
public Connect()
{
}
public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
SetApplicationFields(application);
CommandBar toolBar = null;
toolBar = AddWordToolbar(wordApp, "Ignito Toolbar");
MyButton = this.MakeANewButton(toolBar, "View Tree", 1000, new
_CommandBarButtonEvents_ClickEventHandler(MyButton_Click));
}
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)
{
MyButton.Enabled = false;
}
private void SetApplicationFields(object application)
{
wordApp = (Word.Application)application;
}
private CommandBar AddWordToolbar(Word.Application word, string toolbarName)
{
CommandBar toolBar = null;
try
{
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 CommandBarButton MakeANewButton(CommandBar commandBar, string
caption,int faceID, _CommandBarButtonEvents_ClickEventHandler clickHandler)
{
object missing = System.Reflection.Missing.Value;
try
{
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 MyButton_Click(CommandBarButton SomeButton, ref bool SomeBool)
{
TaxForm = new Form1(this);
TaxForm.Show();
}
}
I have created an Add-in for MS Word. It is a toolbar that contains a button
when you click on button it loads a Form.
My version of office is 2003,
It works well, but with a few problems. if you assume that we have 4 cases
it works at two of them. here is the 4 cases:
1.if you double click on a .doc file to open it, everything goes well (my
button works).
2.if you open a new instance of Word, and use the document as a new document
everything goes well here too.
3. if you have already opened a new instance of word and go to file -> open
(as usual when you open an exsiting .doc file) it does not work, my button
does not opens the form.
4.if you have uploaded a .doc file to Shared Documents on a Sharepoint Site
and want to open it, my Add-in does not work.
here is a bit of my code:
[GuidAttribute("79CC5244-EADC-4F4B-ACF1-9387460BEDF4"),
ProgId("IgnitoAddIn.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
//-------
my variables
//-------
public Connect()
{
}
public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
SetApplicationFields(application);
CommandBar toolBar = null;
toolBar = AddWordToolbar(wordApp, "Ignito Toolbar");
MyButton = this.MakeANewButton(toolBar, "View Tree", 1000, new
_CommandBarButtonEvents_ClickEventHandler(MyButton_Click));
}
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)
{
MyButton.Enabled = false;
}
private void SetApplicationFields(object application)
{
wordApp = (Word.Application)application;
}
private CommandBar AddWordToolbar(Word.Application word, string toolbarName)
{
CommandBar toolBar = null;
try
{
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 CommandBarButton MakeANewButton(CommandBar commandBar, string
caption,int faceID, _CommandBarButtonEvents_ClickEventHandler clickHandler)
{
object missing = System.Reflection.Missing.Value;
try
{
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 MyButton_Click(CommandBarButton SomeButton, ref bool SomeBool)
{
TaxForm = new Form1(this);
TaxForm.Show();
}
}