【发布时间】:2017-02-22 10:47:26
【问题描述】:
我正在尝试在 Word 文档中创建可编辑字段:
Dim bm As Bookmark
If ActiveDocument.Bookmarks.Exists(g_name) = True Then
Set bm = ActiveDocument.Bookmarks(g_name)
End If
If g_var = "DETAILS" Then
bm.Range.Select
With Selection
.Font.Underline = wdUnderlineNone
.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = g_name
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:=g_value, Format:=""
End With
End With
End With
End If
ActiveDocument.Protect Password:="mypass", NoReset:=False, Type:=wdAllowOnlyFormFields
g_name 包含必须插入一些文本的书签的名称,
g_value 包含必须插入书签 g_name 中的文本。
此代码有效,但前提是 g_value 长度小于 255 个字符。如果 g_value 长度大于 255,则宏返回错误“字符串太长”。
我尝试过这样插入文本:
bm.Range.Select
With Selection
.Text = g_value
.Font.Underline = wdUnderlineNone
.Collapse wdCollapseEnd
End With
这个工作,但文本字段是不可编辑的。
如何解决这个问题?
【问题讨论】: