By 拉克塞尔拉格 在14年2020月XNUMX日,星期五
张贴在 Kutools for Word
回复 5
0
观点 5.8
投票 0
在 Word 文档中选择文本,然后单击 Kutools 选项卡下的插入书签图标时,空格不会自动替换为下划线是否有特殊原因? 这似乎是一个完全合乎逻辑、省时的功能,Kutools 可以而且应该迅速实施。 在购买该软件时,我会期待这样的功能,并欢迎任何其他人对此发表评论和/或想法。

Kutools_Insert_Bookmark_ScreenShot.png
你好拉克塞尔拉格,
我有同样的问题/烦恼。 因此,我没有使用 Kutools 创建书签,而是使用以下宏。 如果其他人能从我的工作中受益,我会非常高兴! 
你知道如何使用宏吗?

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年前
·
0喜欢
·
0投票
·
0条评论
·
嘿。

以为我永远不会得到回复,更不用说有宏的了! 非常感谢。

不幸的是,宏对我不起作用。 选择文本并运行宏时,我不断收到 VBA 错误“无法在中断模式下执行代码”。

有什么想法或更正吗?

再次感谢!
·
3年前
·
0喜欢
·
0投票
·
0条评论
·
忘了提到我有时也会收到错误“编译错误:未定义用户定义的类型”
·
3年前
·
0喜欢
·
0投票
·
0条评论
·
哦,哇,所有这些字母和数字都不应该在那里。 让我们再次尝试放置该屏幕截图。
·
3年前
·
0喜欢
·
0投票
·
0条评论
·
您只需要添加正确的参考。 无需确切了解它是什么,只需执行以下操作: 
  1. 转到 VBA 编辑器(即按 ALT+F11)[/*]
  2. 创建一个空的用户表单(请参阅随附的屏幕截图。您在左窗格中右键单击,选择插入,然后选择用户表单。)[/*]
  3. 点击菜单栏上的工具[/*]
  4. 点击参考文献[/*]
  5. 向下滚动到 Microsoft Forms 2.0 对象库[/*]
  6. 确保选中该框[/*]
  7. 点击确定[/*]
再次尝试宏。
·
3年前
·
0喜欢
·
0投票
·
0条评论
·
查看全文