【问题标题】:How create editable field more then 255 characters in Word-VBA?如何在 Word-VBA 中创建超过 255 个字符的可编辑字段?
【发布时间】: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

这个工作,但文本字段是不可编辑的。

如何解决这个问题?

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    只使用文本形式

    word_dev_tools

    并填写此表格

    ActiveDocument.Bookmarks(g_name).Range.Fields(1).Result.Text = g_value
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多