Hi
I could be wrong but as far as I'm aware there is no event to capture keystrokes within a document (or even the application(?)). It's possible on a userform and it's associated controls using KeyUp, KeyDown or KeyPress but they aren't available to the doc.
I'll keep an eye on this to see if I'm proven wrong!
Could you explain why you want to do this? It would be easy to run code that checks for empty paragraphs. However, you are asking for real time checking. That means checking every keystroke. It can not otherwise, as whatever you could come up with has to check each keystroke to see if it IS an Enter key first, and THEN go back and check if the last paragraph is empty.
This seem a rather heavy load. The routine would have to remain in memory the whole time.
I suppose it may be possible, although like Loomah I do not specifically know of a way to do so at the document level. Why is it needed to be real time. Again, a routine to check for empty paragraphs is easy, but it would have to be called, not reside in memory.
It's my utmost last hopeles trial (see my post "Intelligence in MS-Word", about ending the bullet style) to prevent my users, after closing a bulleted list, to enter paragraph after paragraph not in correct style without their being conscious of it. I'm used to programming in C++Builder where it's easy and not heavy load to check all keystrokes. I hoped the same could be the case in VBA.
The best thing I now think to do is setting the next paragraph style of MyBulletListStyle to Body Text. If it is to be a next item in the list the user has to do it with alt-L (shortkey for MyBulletListStyle). I will follow your suggestion to define a ListEnd style to create the space after the list.
I have to say the effort is trying to force something that - in your own words - is a factor of "conscious".
OK, I remember that thread.
You have a MyBulletList style. It should have a Style for following paragraph set as MyBulletList. Why the same? Because there are very few instances where a bulletted list has one bullet. So you want the user to be able to just hit Enter and keep going adding the next item in the list. Right?
So the issue is....what do you do when you get to the end of the list?
You have a MyBulletListEnd style. It is formatted exactly like MyBulletList (but with perhaps an extra space after to make it look better). However, ITS style for following paragraph is Bodytext - or whatever it is you want.
Then....what a surprise...you raise some consciousness, maybe even show the use that it looks better when it done properly. Another way is to make a shortcut key for the End style, something simple, Alt-E perhaps. badda-bing, badda-bam.
If I may suggest...and perhaps my suggestions are not worth much...but it would be far better to have the change (the shortcut key) at the end of the list. Because there is only ONE end. If the user has to use a shortcut key for every item in the list, if they have a 15 items in the list that is 15 extra keystrokes. It is going to, rightly, annoy them.
The issue is ending the list properly. Deal with it there. And you are absolutely correct...it IS a matter of conscious. However, trapping keystrokes in VBA will not do that.
the key code is:
CustomizationContext = ActiveDocument.AttachedTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="Normal.styles.EnterKeyMacro"
and in Normal.styles.EnterKeyMacro I can place the code I want: if one hits Enter in a bulleted list and the paragraph is empty, then I only change the style of the paragraph. In all other cases I do a TypeParagraph.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.