Newbie Office XP PIA question - Add ToolBar

L

Liming

Hi,

I'm 2 days new in developing windows application using Office XP PIA,
I have been an asp.net web developer all this time.

I need to add a toolbar (actually just a button) to office XP and when
user clicks this button, it activates my backend code which extra
content from a webservices and then parse it and attach some content to
word's custom properties.

I have no problem with the webservices part, it's the toolbar part and
how it activates backend code I don't know how to do. I gogoled around
and havne't found a good tutorial. If anybody can point me soemwhere or
show me a bit code, really appreicate it.

Thanks

Liming
 
C

Cindy M -WordMVP-

Hi Liming,

Are you doing an Addin, or automating from within another application?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta
/html/odc_ofcmdbarbest.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;302901
I'm 2 days new in developing windows application using Office XP PIA,
I have been an asp.net web developer all this time.

I need to add a toolbar (actually just a button) to office XP and when
user clicks this button, it activates my backend code which extra
content from a webservices and then parse it and attach some content to
word's custom properties.

I have no problem with the webservices part, it's the toolbar part and
how it activates backend code I don't know how to do. I gogoled around
and havne't found a good tutorial. If anybody can point me soemwhere or
show me a bit code, really appreicate it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
L

Liming

Thanks Cindy, being the holiday, I slacked off a little bit. Just got
back on the horses, really appreicated the information.

I read the code and I did my app, worked well. Though I ran into a
problem.

When the button clicks, it acitivates my web form (a dropdownlist
basically with the datasource retrieved from a webservices). The
problem is that everytime I clicked the button, microsoft word opens up
a new window with the webform.

public void changeStyle_Click(Microsoft.Office.Core.CommandBarButton
barButton, ref bool someBool)
{
object newStyle = "";
/* instantiate my webform */
IFBProperties ifbprop = new IFBProperties();

/* webservices and applicationObject
instantiated in onConnection */
ConnectToIFB(applicationObject);

if(properties!=null)
{
ifbprop.listBox1.DataSource = properties.Tables[0].DefaultView;
ifbprop.listBox1.DisplayMember = "PROP_NAME";
ifbprop.listBox1.ValueMember = "FIELD_CODE";
}

if (ifbprop.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
newStyle = ifbprop.listBox1.Text;
}

if (wordApp != null)
{
this.wordApp.ActiveWindow.Selection.InsertBefore(Convert.ToString(newStyle));

}
}

The problem is I think inside the ConnectToIFB() method. This tries to
attach custom properites to the current document. and inside the
method, I have

....
oDoc = this.wordApp.Documents.Add(ref oMissing, ref oMissing, ref
oMissing,
ref oMissing);
......

I think this method invokes a new window? Any suggestions is
appreicated. Thanks
 
C

Cindy M -WordMVP-

Hi Liming,

Below... Note I'm not 100% certain I'm following the problem, but I've put down my
thoughts...
When the button clicks, it acitivates my web form (a dropdownlist
basically with the datasource retrieved from a webservices). The
problem is that everytime I clicked the button, microsoft word opens up
a new window with the webform.

public void changeStyle_Click(Microsoft.Office.Core.CommandBarButton
barButton, ref bool someBool)
{
object newStyle = "";
/* instantiate my webform */
IFBProperties ifbprop = new IFBProperties();

/* webservices and applicationObject
instantiated in onConnection */
ConnectToIFB(applicationObject);

if(properties!=null)
{
ifbprop.listBox1.DataSource = properties.Tables[0].DefaultView;
ifbprop.listBox1.DisplayMember = "PROP_NAME";
ifbprop.listBox1.ValueMember = "FIELD_CODE";
}

if (ifbprop.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
newStyle = ifbprop.listBox1.Text;
}

if (wordApp != null)
{
this.wordApp.ActiveWindow.Selection.InsertBefore(Convert.ToString(newStyle));

}
}

The problem is I think inside the ConnectToIFB() method. This tries to
attach custom properites to the current document. and inside the
method, I have

....
oDoc = this.wordApp.Documents.Add(ref oMissing, ref oMissing, ref
oMissing,
ref oMissing);
......

I think this method invokes a new window?
Well, what it does is to create a new Word document, everytime it's called. Given
the default pseudo-MDI interface of Word 2000 and later, this will open in a new
Word window, although the application should continue to handle it as part of the
same application instance of Word. (You can confirm this by seeing whether all the
documents are listed in the Windows menu.)

You're creating a new document here, and assigning it to an object variable, which
is very good. But are you then USING this object variable later? I get the feeling
you should be using it instead of (part of) the following

this.wordApp.ActiveWindow.Selection.InsertBefore(Convert.ToString(newStyle)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in
the newsgroup and not by e-mail :)
 

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

Top