get current AddinModule instance

Add-in Express™ Support Service
That's what is more important than anything else

get current AddinModule instance
 
Christian Green




Posts: 9
Joined: 2009-03-04
i am trying to get the wordapp from the addinmodule class but if i instantiate a new one the wordapp property is null. how can i call the addinmodule and get the current instance?

AddinModule localAddin ;//=new AddinModule();

Word.Dialog dlg = localAddin.WordApp.Application.Dialogs.Item(Word.WdWordDialog.wdDialogFormatFont);
int j = localAddin.WordApp.Application.Dialogs.Item(Word.WdWordDialog.wdDialogFormatFont).Display(ref object);
System.Type dlgType = typeof(Word.Dialog);

////// Pop up font format window.

//int j = dlg.Display(ref localOject);
// MessageBox.Show("You clicked: " + j.ToString());
if (j == -1)////// -1 means they clicked on "ok".
{
string s = (string)dlgType.InvokeMember("Font", System.Reflection.BindingFlags.GetProperty, null, dlg, null, System.Globalization.CultureInfo.InvariantCulture);
MessageBox.Show(s);

}
//Word.Range localRange;//=new Word.Range;

//define you Range object here.
Word.Document doc = localAddin.WordApp.Application.ActiveDocument;
object start = 0;
object end=doc.Characters.Count + 1;
Word.Range localRange = doc.Range(ref start, ref end);
Posted 02 Apr, 2009 09:52:05 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Christian.

Please use the code below to get an instance of Word application.

Microsoft.Office.Interop.Word._Application wordApp = this.HostApplication as Microsoft.Office.Interop.Word;
Posted 02 Apr, 2009 10:01:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Or just use the this.WordApp.Application property to access Word application from the addinmodule.
Posted 02 Apr, 2009 10:06:23 Top
Christian Green




Posts: 9
Joined: 2009-03-04
Sergey Grischenko wrote:
Hi Christian.

Please use the code below to get an instance of Word application.

Microsoft.Office.Interop.Word._Application wordApp = this.HostApplication as Microsoft.Office.Interop.Word;


I am trying to do this from a winForm, that i get to open when i press a button on the ribbon control
Posted 02 Apr, 2009 12:29:28 Top
Eugene Astafiev


Guest


Hello Christian,

In that case you need to pass an instance of the Word application to your winform application.
Posted 03 Apr, 2009 04:14:12 Top
Christian Green




Posts: 9
Joined: 2009-03-04
Eugene Astafiev wrote:
Hello Christian,

In that case you need to pass an instance of the Word application to your winform application.


That's exactly what i am trying to do but i am not going about it correctly, can you please advise.
Posted 03 Apr, 2009 08:41:58 Top
Andrei Smolin


Add-in Express team


Posts: 18806
Joined: 2006-05-11
Hello Christian,

MyAddin1.AddinModule module = AddinExpress.MSO.ADXAddinModule.CurrentInstance as MyAddin1.AddinModule;


Now you can access module.WordApp.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Apr, 2009 08:57:18 Top