Ilya Cherkasov

Hi all!

I have an issue with opened documents.

When I do this:

FileInfo documentFile = _tempSaver.GetFromEdition(e.Data);

string documentPath = documentFile.FullName;

object boxedDocumentPath = ( object )documentPath;

object visible = ( object )true;

Microsoft.Office.Interop.Word.Document document = _thisAddIn.Application.Documents.Add(ref boxedDocumentPath, ref _null, ref _null, ref visible);

I see that Word instantly get's focus on newly opened document, and the next moment I see document that was the previous before adding new one.

I try to

document.Activate();

document.Application.ActiveWindow.SetFocus();

But still focus returns on that document that was current before openening new.

Is there a way to workaround this issue (I just need the focus stopped when i open new doc). I hope there is or else my users will eat my stomach.

Hope to hearing from you,

Ilya Cherkasov

RBC Soft.



Re: Visual Studio Tools for Office Howto set focus on newly opened word document (W 2003)

Cindy Meister

Is any kind of dialog box open in the Word application when you try to set focus to the new document

Word will normally leave the focus in the new document, unless something is interfering and forcing it back to another window. A dialog box would be the most common cause.






Re: Visual Studio Tools for Office Howto set focus on newly opened word document (W 2003)

Ilya Cherkasov

Of course there is a usercontrol wrapped in form that initiates code I posted before. User doubleclicks on selected document and then I add it to documents collection.

In fact, I close this form before adding new document.

Is there any way to determine what causes word to focus back Some way to see some stuff that interfers with normal Word behaviour





Re: Visual Studio Tools for Office Howto set focus on newly opened word document (W 2003)

Cindy Meister

Which version of Word are you working with There was an older version (2000 or 2002, can't remember which) where this was a problem in Word...






Re: Visual Studio Tools for Office Howto set focus on newly opened word document (W 2003)

Ilya Cherkasov

It's Microsoft Office Word 2003 SP2





Re: Visual Studio Tools for Office Howto set focus on newly opened word document (W 2003)

Ji Zhou ¨C MSFT

Hi llya,

My thought is set a flag to true in the event handle which you use to add the document. And then in WindowActive event handle to test whether the flag is true. If yes, set the new added document to be active and flag to false. The new added documentĄ¯s index always is 1 in the documents collection.

Also refer the following thread to see if it helps:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1828872&SiteID=1

Thanks

Ji