Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
插入单词表标题vba:标题字符限制_Vba_Vbscript_Ms Word - Fatal编程技术网

插入单词表标题vba:标题字符限制

插入单词表标题vba:标题字符限制,vba,vbscript,ms-word,Vba,Vbscript,Ms Word,我有一个非常简单的函数,它从变量txt中提取字符串,并使用InsertCaption将其转换为标题。此时,我可以向该函数传递一个非常长的字符串(超过255个字符),但不知何故,InsertCaption仍然会截断变量txt,并将大小限制为255。有办法解决这个问题吗?我可以破解这个函数吗?谢谢 appWD.Selection.InsertCaption Label:=Lbl, _ Title:=txt & txt, _

我有一个非常简单的函数,它从变量
txt
中提取字符串,并使用
InsertCaption
将其转换为标题。此时,我可以向该函数传递一个非常长的字符串(超过255个字符),但不知何故,
InsertCaption
仍然会截断变量
txt
,并将大小限制为255。有办法解决这个问题吗?我可以破解这个函数吗?谢谢

appWD.Selection.InsertCaption Label:=Lbl, _
                              Title:=txt & txt, _
                              Position:=0, _
                              ExcludeLabel:=0   'wdCaptionPositionAbove = 0

这似乎是Word VBA中的一个限制。有许多限制文本为255个字符,这些字符来自早期的WordBasic时代。(VBA对象模型覆盖旧的WordBasic。)

解决此问题的一种方法是检查分配给标题的字符串是否超过255个字符。如果是,则将余数附加到标题中。例如:

Sub InsertCaptionLongerThan255Chars()
    Dim tbl As Word.Table
    Dim sCapText As String
    Dim rngCap As word.Range

    Set tbl = ActiveDocument.Tables(1)
    sCapText = String(400, "x")
    tbl.Range.InsertCaption "Table", sCapText
    If Len(sCapText) > 255 Then
        'The selection in the document moves to the new caption
        Set rngCap = Selection.Range.Paragraphs(1).Range
        'Put the target at the end of the caption's paragraph
        rngCap.Collapse wdCollapseEnd
        rngCap.MoveEnd wdCharacter, -1
        'Add the remainder of the text
        rngCap.Text = Mid(sCapText, 256)
    End If
End Sub

这似乎是Word VBA中的一个限制。有许多限制文本为255个字符,这些字符来自早期的WordBasic时代。(VBA对象模型覆盖旧的WordBasic。)

解决此问题的一种方法是检查分配给标题的字符串是否超过255个字符。如果是,则将余数附加到标题中。例如:

Sub InsertCaptionLongerThan255Chars()
    Dim tbl As Word.Table
    Dim sCapText As String
    Dim rngCap As word.Range

    Set tbl = ActiveDocument.Tables(1)
    sCapText = String(400, "x")
    tbl.Range.InsertCaption "Table", sCapText
    If Len(sCapText) > 255 Then
        'The selection in the document moves to the new caption
        Set rngCap = Selection.Range.Paragraphs(1).Range
        'Put the target at the end of the caption's paragraph
        rngCap.Collapse wdCollapseEnd
        rngCap.MoveEnd wdCharacter, -1
        'Add the remainder of the text
        rngCap.Text = Mid(sCapText, 256)
    End If
End Sub

这是哪个版本的单词?您能否以用户身份在Word UI中创建长度超过255个字符的标题?Word确实有大约255个字符的限制,特别是在VBA中,但我不知道这是否是其中之一,而且目前我还没有在一台机器上进行研究…@Cindymister,谢谢你的评论。我正在Windows 7中使用Word 2013。我必须在VBA中创建长标题。到目前为止,我试图拆分字符串并使用“代码> TypeText < /CODE”插入保留部分。我询问UI是为了测试目的,而不是作为解决方案。@ CindyMeister,刚刚尝试过,它没有产生错误消息,但我不能判断Word是否考虑长字符串作为标题……这是哪个版本的单词?您能否以用户身份在Word UI中创建长度超过255个字符的标题?Word确实有大约255个字符的限制,特别是在VBA中,但我不知道这是否是其中之一,而且目前我还没有在一台机器上进行研究…@Cindymister,谢谢你的评论。我正在Windows 7中使用Word 2013。我必须在VBA中创建长标题。到目前为止,我试图拆分字符串并使用“<代码> TypeText < /CODE”插入保留部分。我询问了UI的测试目的,而不是作为解决方案。@ CindyMeister,刚刚尝试过,它没有产生错误消息,但是我不能判断Word是否把长字符串作为标题来考虑…