Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2013, 02:16 PM
AlexR AlexR is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows XP Show userform without losing document focus? Or other method to get a graphic to pop? Office 2007
Novice
Show userform without losing document focus? Or other method to get a graphic to pop?
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Post Show userform without losing document focus? Or other method to get a graphic to pop?

Hi all,



I'm trying to figure out a way to show a userform without taking the focus off the document. Actually to be more accurate, I'm trying to generate some visual feedback when a user types certain words spelled correctly. Perferably a little animated gif of a firework or something like that.

The only way I can see to show a graphic is to show a userform with the graphic on it. Is there some other way? (I'm having a hard time Googling this problem, since the inclusion of the word "graphic" tends to return only ways to insert graphics into the document, though actually that might even be a way to do this if I can insert it and remove it right away. )

The trouble with the userform is that it takes the focus off the document and interrupts typing. Since this is supposed to be positive feedback, I need it to be unobtrusive. Having to dismiss the userform every time is annoying, and setting them up to automatically close doesn't seem to be possible in less than a second, which is still pretty obtrusive.

Does anyone have any suggestions or even completely different ideas to accomplish this?

Thanks so much!
Reply With Quote
  #2  
Old 03-28-2013, 03:58 PM
gmaxey gmaxey is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows 7 32bit Show userform without losing document focus? Or other method to get a graphic to pop? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Use a modeless form:
Sub CallForm
Userform1.Show vbModeless
End Sub


and place the following code in the form activate event:

Private Sub UserForm_Activate()
Selection.Range.Select
Application.Activate
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 03-28-2013, 05:32 PM
AlexR AlexR is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows XP Show userform without losing document focus? Or other method to get a graphic to pop? Office 2007
Novice
Show userform without losing document focus? Or other method to get a graphic to pop?
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Default

Ah, thank you!! I combined your answer with some code I found elsewhere for a perfect result!

I'm using this to automatically close the Userform:

Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
 
Private Sub UserForm_Activate() 
    DoEvents 
    Sleep 500 
    Unload Me 
End Sub
(Source: http://www.ozgrid.com/forum/showthread.php?p=506767)


I also came up with this, to close the form with any keystroke and return the character, but I'm still getting some wonky results with non-alphanumeric keys. Your way works better, but just in case this might be useful to someone else:
Code:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If Shift = 0 Then Selection.TypeText LCase(Chr(KeyCode))
    If Shift = 1 Then Selection.TypeText Chr(KeyCode)
    Unload Me
End Sub
Reply With Quote
  #4  
Old 03-29-2013, 04:14 AM
gmaxey gmaxey is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows 7 32bit Show userform without losing document focus? Or other method to get a graphic to pop? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Alex,

With your code (either of them) I don't see how you have returned the focus to the document. In fact the KeyDown would only work if the Userform had the focus. If that is acceptable, then perhaps:

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Selection.TypeText Chr(KeyAscii)
Unload Me
End Sub

How are you triggering the display of your userform?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 03-30-2013, 08:23 PM
AlexR AlexR is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows XP Show userform without losing document focus? Or other method to get a graphic to pop? Office 2007
Novice
Show userform without losing document focus? Or other method to get a graphic to pop?
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Default

Hi Greg,

I was triggering it with just:

Userform1.Show

I was unaware of the vbModeless option until now. (Or perhaps you meant in more detail what leads to the triggering of the userform?)

It doesn't really matter if the userform has focus or not as long as the end result is that the user can keep typing without interruption. So you're right that my method didn't return the focus to the document. Instead it captured the last keystroke and both used it to close the userform and returned it to the document. The end result was that the user would see the popup for a moment without having to do anything to close it.

It's interesting that your KeyPress suggestion doesn't give me the issue with the wonky ascii codes that KeyDown does. I wonder what's working differently there. But regardless, the vbModeless suggestion does what I want better than I thought it could be done. Ideally I'd like a transparent animation to pop up, but it seems such things are impossible in the context of VBA.
Reply With Quote
  #6  
Old 03-31-2013, 05:14 AM
gmaxey gmaxey is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows 7 32bit Show userform without losing document focus? Or other method to get a graphic to pop? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Or perhaps you meant in more detail what leads to the triggering of the userform?

Exactly, I haven't checked lately, but I don't think the windows selection change event fires each time you type a character, so how are you determining when the user types a word correctly to automatically trigger you pop-up.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 03-31-2013, 09:40 AM
AlexR AlexR is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows XP Show userform without losing document focus? Or other method to get a graphic to pop? Office 2007
Novice
Show userform without losing document focus? Or other method to get a graphic to pop?
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Default

Well, to be honest I'm still working out the details of that, but the idea is that as the user types, the macro checks each word against a list of commonly misspelled words and a running list of frequently misspelled words specific to the user. This particular userform triggers the first few times the words are spelled correctly. A misspelling triggers a different userform that forces the user to retype the word correctly before continuing. After much research the only method I've found is to bind the macro to the spacebar and trigger it that way. I may also have to bind it to all the punctuation and closing brackets, which is ridiculous, but there doesn't appear to be a way to piggyback on Word's built-in spell checker (though its collections can be accessed with in from VBA) or to watch what the user is typing as s/he types.

I'm getting the basics from what this guy is doing here: http://www.vbaexpress.com/kb/getarticle.php?kb_id=204

The next challenge will be to maintain the running list between uses of Word, which I'll probably do by generating a text file and reimporting it. We'll see how it works out. I try to refrain from asking questions unless I'm genuinely stuck lest I use up the good will of helpful experts like yourself.
Reply With Quote
  #8  
Old 03-31-2013, 12:17 PM
AlexR AlexR is offline Show userform without losing document focus? Or other method to get a graphic to pop? Windows XP Show userform without losing document focus? Or other method to get a graphic to pop? Office 2007
Novice
Show userform without losing document focus? Or other method to get a graphic to pop?
 
Join Date: Mar 2013
Location: Eastern PA, USA
Posts: 8
AlexR is on a distinguished road
Default

Ok, as it turns out I might not be able to bind the macro to all the punctuation. This warrants another thread, however...
Reply With Quote
Reply

Tags
document focus, graphics, userform

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show userform without losing document focus? Or other method to get a graphic to pop? Losing charts in Word document sweetpotater Word 1 04-24-2012 04:46 AM
Show userform without losing document focus? Or other method to get a graphic to pop? How to link userform to another word document SaneMan Word VBA 5 10-14-2011 05:12 AM
Show userform without losing document focus? Or other method to get a graphic to pop? Setting focus to specific word document from UserForm SaneMan Word VBA 5 04-01-2011 03:11 PM
I have a Word 2007 document that only show 13 pages xeonix Word 0 07-06-2009 08:38 PM
Show userform without losing document focus? Or other method to get a graphic to pop? Graphic files do not appear in my document plt Drawing and Graphics 2 04-22-2009 09:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft