Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2022, 11:08 AM
Matt C's Avatar
Matt C Matt C is offline Prevent customisation/keybinding of "Enter" key from breaking AutoText function Windows 10 Prevent customisation/keybinding of "Enter" key from breaking AutoText function Office 97-2003
Advanced Beginner
Prevent customisation/keybinding of "Enter" key from breaking AutoText function
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Question Prevent customisation/keybinding of "Enter" key from breaking AutoText function

Hi folks



I'm trying to work out how to keep Word 2003's AutoText function intact after creating a key binding for the Enter key.

With the key binding set, AutoText gets as far as bringing up the auto-complete suggestion tip, but pressing Enter does not add the text (as it's just following the instructions in the macro).

I could, in theory, remove the Enter customisation completely, but I'd prefer not to as I want a couple of things to happen like updating fields and populating the status bar with a message.

Is there any way of overcoming this? Here's how my coding looks:

Quote:
Sub SetSmartKeys()

CustomizationContext = ActiveDocument

KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), KeyCategory:= _
wdKeyCategoryMacro, Command:="SmartEnter"

End Sub
Quote:
Sub SmartEnter()

' Word default action

Selection.TypeParagraph

' Update fields, then show some tips in the status bar

Application.Run MacroName:="UpdateFields"
Application.Run MacroName:="SmartKeyHelp"

End Sub
Without this key customisation, the AutoText function works normally.
Reply With Quote
  #2  
Old 02-07-2022, 08:48 PM
Guessed's Avatar
Guessed Guessed is offline Prevent customisation/keybinding of "Enter" key from breaking AutoText function Windows 10 Prevent customisation/keybinding of "Enter" key from breaking AutoText function Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Have you tried the F3 key instead of trying to kick off Autotext by using the Enter key?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-08-2022, 05:31 AM
Matt C's Avatar
Matt C Matt C is offline Prevent customisation/keybinding of "Enter" key from breaking AutoText function Windows 10 Prevent customisation/keybinding of "Enter" key from breaking AutoText function Office 97-2003
Advanced Beginner
Prevent customisation/keybinding of "Enter" key from breaking AutoText function
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Have you tried the F3 key instead of trying to kick off Autotext by using the Enter key?
I could do that, yes, but I want to know if there's any way of clearing up the "Enter" issue in case I want to share the template. The tip which pops up says "Press ENTER to insert".

(Also, being a touch-typist, it's much more intuitive for me to press Enter rather than F3.)
Reply With Quote
  #4  
Old 02-09-2022, 05:16 PM
Guessed's Avatar
Guessed Guessed is offline Prevent customisation/keybinding of "Enter" key from breaking AutoText function Windows 10 Prevent customisation/keybinding of "Enter" key from breaking AutoText function Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm not able to test but perhaps this concept would work unless the selection range is exactly the same size as the autotext being inserted
Code:
Sub SmartEnter()
  Dim iStart As Long, iEnd As Long
  iStart = ActiveDocument.Range.End - Len(Selection.Range.Text)   'assumes typing replaces selection
  Selection.TypeParagraph     ' Word default action
  iEnd = ActiveDocument.Range.End
  If iStart <> iEnd - 1 Then
    MsgBox "No autotext insertion"
  Else
    MsgBox "Autotext insertion"
  End If
  
  ' Update fields, then show some tips in the status bar
'  Application.Run MacroName:="UpdateFields"
'  Application.Run MacroName:="SmartKeyHelp"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro Matt C Excel Programming 2 01-08-2022 06:03 AM
Conditional function to operate a formula based on "Yes" or "No" Condition Des ONeill Excel 1 07-03-2021 12:17 AM
Condtional function to operate a formula based on "Yes" or "No" Des ONeill Excel 3 07-03-2021 12:16 AM
Keybinding 3 keys throws an "issue" rjrichar40 Word VBA 1 08-13-2014 07:42 AM
Prevent customisation/keybinding of &quot;Enter&quot; key from breaking AutoText function How do I prevent the "author" or "owner" fields from being changed? Bones Word 3 06-08-2012 12:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:09 PM.


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