Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Set focus back to Word document after closing dialog box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LostInMD - 05 Oct 2006 19:20 GMT
Hi,

I am loading word with vb2005 customized commandbars.  I am having
difficulty "activating" the open document within the word application after I
close the dialogbox (that is loaded upon the user clicking one of the
commandbar buttons).  After I close my dialog box, I see the ibeam cursor in
my word document, however it is not flashing, just a solid vertical line.  I
have tried .Activate for the application and active document.  If I put a
breakpoint at the .Activate line of code, F5 to the breakpoint, then F5 to
the end of the code, focus is set back to the document and I do have a
blinking cursor.  However, if I just F5 all the code (without the
breakpoint), I do not have a blinking cursor.  I have tried typing text into
the document after activating the document -->
Application.Selection.TypeText("test") and
Application.Selection.TypeBackspace().  I have tried -->
Application.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekMainDocument -->
and still no luck.  I am using form.ShowDialog() to display the dialog box
and have tried using form.Close() and also just setting the form = nothing
(without form.Close()).  I thank you in advance for any information you can
offer!
zkid - 05 Oct 2006 21:15 GMT
Have you tried this?

If Tasks.Exists("Microsoft Word") = True Then Tasks("Microsoft Word").Activate

> Hi,
>
[quoted text clipped - 17 lines]
> (without form.Close()).  I thank you in advance for any information you can
> offer!
LostInMD - 05 Oct 2006 21:21 GMT
Hi zkid,

Thanks for the suggestion.  I tried out Application.Tasks........ and it did
not work.  I appreciate the thought!

> Have you tried this?
>
[quoted text clipped - 21 lines]
> > (without form.Close()).  I thank you in advance for any information you can
> > offer!
zkid - 05 Oct 2006 21:39 GMT
Hmmm.  What do you mean by dialog box?  Are you calling one of Word's default
dialogs, or are you talking about a userform?  

If a dialog, how are you calling it?

If a userform, how are you closing/unloading it?  Please provide the calling
and closing code for either.

> Hi zkid,
>
[quoted text clipped - 26 lines]
> > > (without form.Close()).  I thank you in advance for any information you can
> > > offer!
LostInMD - 06 Oct 2006 13:49 GMT
A dialog box in the sense of:  I created a vb2005 windows form with an OK and
Cancel button.  I display the form with:  frm.ShowDialog().  I get the cannot
place focus back onto the document when the user closes the form via the
cmdCancel_Click() event where I have : frm.Close().  I also get the same
issue when the user simply clicks the "x" in the upper right corner of the
form/dialogbox.  Thanks again for all your help!

> Hmmm.  What do you mean by dialog box?  Are you calling one of Word's default
> dialogs, or are you talking about a userform?  
[quoted text clipped - 34 lines]
> > > > (without form.Close()).  I thank you in advance for any information you can
> > > > offer!
zkid - 06 Oct 2006 20:34 GMT
Ah, okay, you need VB help.  This is the VBA forum.  

Anyway, I found this code on google by searching for VB activate application.

Link = http://www.developerfusion.co.uk/show/126/

//You can activate another application by using the AppActivate statement.
Simply provide the text in its titlebar:

//The shell function returns a TaskID (double), that you can use with the
AppActivate statement:

Private dblWordID As Double
'// runs word
Private Sub cmdRunWord_Click()
   dblWordID = Shell("notepad", vbNormalFocus)
End Sub
'// activates word at a later stage
Private Sub cmdActivateWord_Click()
   AppActivate dblWordID
End Sub

Here's another link to close a dialog box while hooking the user's
responses:  
http://www.vbaccelerator.com/home/VB/Code/Libraries/Common_Dialogs/Hooked_Common
_Dialogs/article.asp


I think the problem is with the way your VB form closes.  If none of the
above works, please try searching google for vb forums.

> A dialog box in the sense of:  I created a vb2005 windows form with an OK and
> Cancel button.  I display the form with:  frm.ShowDialog().  I get the cannot
[quoted text clipped - 41 lines]
> > > > > (without form.Close()).  I thank you in advance for any information you can
> > > > > offer!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.