Ուրբաթ, 14 թ. Փետրվարի 2020-ին
  5 Գրառումներ
  5.5K այցելություններ
0
Քվեարկել
արձակել
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 տարի առաջ
·
#2077
0
Քվեարկել
արձակել
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 տարի առաջ
·
#2078
0
Քվեարկել
արձակել
Ողջույն.

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 տարի առաջ
·
#2079
0
Քվեարկել
արձակել
forgot to mention that I also sometimes get the error "Compile error: User-defined type not defined"
3 տարի առաջ
·
#2080
0
Քվեարկել
արձակել
Oh wow, all those letters and digits aren't supposed to be there. Let's try putting that screenshot again.
Հավելվածներ (1)
3 տարի առաջ
·
#2081
0
Քվեարկել
արձակել
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.
Հավելվածներ (1)
  • էջ:
  • 1
Այս գրառման համար դեռևս պատասխաններ չեն տրվել: