why every button click opens up a new window? Office PIA

L

Liming

Hello,

I have a command button and it activates a web form, so far so good.
Now, inside the webform, I I try to retrieve some data from a
webservices by calling another method and add custom propreties to the
current doucment. This is when hell break loose. Every click, it opens
up the webform in a NEW word document instead of the current document.
Here is my code

private void ConnectToIFB(object application)
{
Word._Document oDoc;

object oDocCustomProps;
object oMissing = System.Reflection.Missing.Value;

// Retreive custom properties from web services

......


//Add a property/value pair to the CustomDocumentProperties
collection.

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

oDocCustomProps = oDoc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();


.....
// attach custom properties

}


Is it the problem with the "this.wordApp.Documents.Add"?
 
L

Liming

resolved. I changed

oDoc = this.wordApp.Documents

to

oDoc = this.wordApp.ActiveDocument

Thanks.
 
C

Cindy M -WordMVP-

Hi Liming,

Seems to me I answered this elsewhere yesterday, but...
Is it the problem with the "this.wordApp.Documents.Add"?
Certain is, that this will always generate a new document,
and that that document will appear in a new window (due to
how Word is designed). It should still be the same instance
of Word (wordApp is valid).

If you already have a Word document when ConnectToIFB is
called, then you need to do something more like this:

Word.Document oDoc = this.wordApp.ActiveDocument;

(Although I don't really understand why you're using
this.wordApp, and at the same time passing an application
as an object to the procedure...)

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 Once again. I actually tried this.wordApp.ActiveDocument.
Builded in, installed it (within visual studio.net) and pressed F5.
didn't work.

I posted my sample code on another thread here

http://groups.google.com/group/micr...add_ins/browse_thread/thread/1ff63893559e977e

Not my code exactly, but i followed the exact format and method. The
only difference is that I got rid of the excel related fields.

I'm still experecing the same problem. When commandbar is clicked, word
first opens up in a new window and then my pop up will show up in the
new window.

I'll post my exact code later tonight when I get home, mabye you can
see it better that way.
 
C

Cindy M -WordMVP-

Hi Liming,
I actually tried this.wordApp.ActiveDocument.
Builded in, installed it (within visual studio.net) and pressed F5.
didn't work.
It always helps when you describe exactly HOW something didn't work.

I'd also appreciate an explanation for the object you're passing to
this function. I suspect you ought to be using that (coverting it
explicitly to the Word application), roughly:

Word.Application wdApp = (Word.Application) application
Word.Document oDoc = wdApp.ActiveDocument

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

Just checking back and wanne thank you for your help during the time.

I was being stupid because after I added Word.Document oDoc =
this.wordApp.ActiveDocument; I didn't comment out the original
statment, so of course, it still opens up a new document.

Right now, as the app continues on, I noticed a new bug which is after
I clicked the button after the first time, the windows form pops up and
after that, any subsequent clicks, has not reactions what's so ever.
Anyway, I might post a different thread about this.

Again, thank you so much.
 
Top