Skip to main content
Support is Offline
Today is our off day. We are taking some rest and will come back stronger tomorrow
Official support hours
Monday To Friday
From 09:00 To 17:30
  Friday, 14 February 2020
  5 Replies
  5.3K Visits
0
Votes
Undo
Is there a particular reason why spaces aren't automatically replaced with underscores when selecting text in a Word Document, and then clicking on the Insert Bookmark icon under the Kutools tab?  This seems like an entirely logical, time-saving feature that Kutools can, and should, implement promptly.  I would've expected such a feature when purchasing the software, and welcome any others' comments and/or thoughts on the same.

Kutools_Insert_Bookmark_ScreenShot.png
3 years ago
·
#2077
0
Votes
Undo
Hello laxerlager,
I have the same problem/annoyance. So instead of using Kutools to create the bookmark, I use the following macro. It would make me very happy if someone else than could benefit from my work! 
You know how to use macros?

Sub InsertNewBookmark()
Dim MyData As DataObject
Dim strClip As String
Dim bkName As String
 
If Selection.Type = wdSelectionNormal Then
 Selection.Copy
End If
Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText
strClip = Trim(strClip)
strClip = Replace(strClip, " ", " ")
strClip = Replace(strClip, "  ", " ")
strClip = Replace(strClip, " ", "_")
bkName = InputBox("Insert new bookmark name.", "Hello there.", strClip)
 
On Error GoTo Oops
If (StrPtr(bkName) = 0) Then
' MsgBox "You pressed cancel or [X]."
Exit Sub
 
ElseIf (bkName = "") Then
MsgBox "You have to name the bookmark. Try again."
Call InsertNewBookmark
 
Else
 ActiveDocument.Bookmarks.Add _
 Name:=bkName, Range:=Selection.Range
Exit Sub
End If
Oops:
MsgBox ("The bookmark could not be created. Remember to follow these guidelines :" & vbNewLine & vbNewLine & "• Names must begin with a letter of the alphabet." _
& vbNewLine & "• Names can contain only letters, numbers, and the underscore." & vbNewLine & "• Names cannot contain spaces or punctuation marks." & vbNewLine _
& vbNewLine & "Let's try it again. Ready?")
Call InsertNewBookmark
 
End Sub
3 years ago
·
#2078
0
Votes
Undo
Hey there.

Thought I would never get a reply, let alone one with a Macro! Thanks so much.

Unfortunately, the Macro does not work for me. When selecting text and running the macro, I keep getting a VBA Error "Can't execute code in break mode".

Any thoughts or corrections?

Thanks again!
3 years ago
·
#2079
0
Votes
Undo
forgot to mention that I also sometimes get the error "Compile error: User-defined type not defined"
3 years ago
·
#2080
0
Votes
Undo
Oh wow, all those letters and digits aren't supposed to be there. Let's try putting that screenshot again.
3 years ago
·
#2081
0
Votes
Undo
You just need to add the proper reference. No need to understand exactly what it is, just do the following: 
  1. Go to the VBA editor (that is, press ALT+F11)[/*]
  2. Create an empty userform (see screenshot attached. You right click in the left pane, select insert, then Userform.) [/*]
  3. Click on Tools on the menu bar[/*]
  4. Click on References[/*]
  5. Scroll down to Microsoft Forms 2.0 Object Library[/*]
  6. Make sure the box is checked[/*]
  7. Click OK[/*]
Try the macro again.
  • Page :
  • 1
There are no replies made for this post yet.