|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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! |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 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 |
#4
|
|||
|
|||
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? |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
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. |
#8
|
|||
|
|||
Ok, as it turns out I might not be able to bind the macro to all the punctuation. This warrants another thread, however...
|
Tags |
document focus, graphics, userform |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Losing charts in Word document | sweetpotater | Word | 1 | 04-24-2012 04:46 AM |
How to link userform to another word document | SaneMan | Word VBA | 5 | 10-14-2011 05:12 AM |
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 |
Graphic files do not appear in my document | plt | Drawing and Graphics | 2 | 04-22-2009 09:58 AM |