Set focus back to Word document after closing dialog box

L

LostInMD

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!
 
Z

zkid

Have you tried this?

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

LostInMD

Hi zkid,

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

zkid

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.
 
L

LostInMD

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!
 
Z

zkid

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.
 

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