0

Is there a built-in or VBA method to place a tab stop at the exact location of the text cursor?

I've tried digging through documentation, but I can't figure out how to get the text cursor location.

I originally needed this to replace the exact distance of two standard spaces, but I discovered 1/4 Em Spaces are the same size, but don't stretch when aligned to justified.

1 Answer 1

0

I stumbled upon the answer right after posting. 😅 Text cursor is called "Selection" in VBA.

Here is the Procedure Sub, and a Sub to bind it to Ctrl+Shift+Tab. Add this as VBA to your Normal.dotm to use in all your documents. 😊

Public Sub InsertTabStop()
  Selection.Paragraphs.TabStops.Add (Selection.Information(wdHorizontalPositionRelativeToTextBoundary))
End Sub
 
Sub AddKeyBind()
  Dim KeyCode As Long
  'Change the keys listed in "BuildKeyCode" to change the shortcut.
  KeyCode = BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyTab)
 
  CustomizationContext = NormalTemplate
  If FindKey(KeyCode).Command = "" Then
    KeyBindings.Add wdKeyCategoryMacro, "InsertTabStop", KeyCode
  Else
    MsgBox "Error: Key combination is already in use!" & vbNewLine & vbNewLine & "Key binding not set.", vbOKOnly + vbCritical, "Key binding failed"
  End If
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.