我有一些我想運行的代碼 - 但 Word 中的書簽不斷被洗掉 - 我希望它“覆寫”最后一個 Input 而不是添加它。
Dim NAME As Range
Set NAME = ActiveDocument.Bookmarks("Username").Range
NAME.Text = Me.TextName.Value
Dim Surname As Range
Set Surname = ActiveDocument.Bookmarks("UsernameSurname").Range
Surname.Text = Me.TextSurname.Value
有人對此有解決方案嗎?謝謝。
uj5u.com熱心網友回復:
您的代碼不會洗掉書簽 - 它只是在它們之后插入內容。
要更新書簽,您可以使用,例如:
Call UpdateBookmark("Username",Me.TextName.Value)
Call UpdateBookmark("UsernameSurname",Me.TextSurname.Value)
加上:
Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
If .Bookmarks.Exists(StrBkMk) Then
Set BkMkRng = .Bookmarks(StrBkMk).Range
BkMkRng.Text = StrTxt
.Bookmarks.Add StrBkMk, BkMkRng
End If
End With
Set BkMkRng = Nothing
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/485915.html
