Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
Word VBA:在文档末尾添加带内嵌文本包装的文本框_Vba_Ms Office_Ms Word_Word 2013 - Fatal编程技术网

Word VBA:在文档末尾添加带内嵌文本包装的文本框

Word VBA:在文档末尾添加带内嵌文本包装的文本框,vba,ms-office,ms-word,word-2013,Vba,Ms Office,Ms Word,Word 2013,我正在尝试编写一个宏,它将在Word文档中插入文本框,并按照文本换行设置它们的格式 以下是我目前的代码: Sub Example() Dim newTextbox As Shape For I = 1 To 10 Set newTextbox = ActiveDocument.Shapes.AddTextbox _ (Orientation:=msoTextOrientationHorizontal, _ Left:=0, Top:

我正在尝试编写一个宏,它将在Word文档中插入文本框,并按照文本换行设置它们的格式

以下是我目前的代码:

Sub Example()
    Dim newTextbox As Shape
    For I = 1 To 10
        Set newTextbox = ActiveDocument.Shapes.AddTextbox _
        (Orientation:=msoTextOrientationHorizontal, _
        Left:=0, Top:=0, Width:=100, Height:=50)
        newTextbox.WrapFormat.Type = wdWrapInline
        newTextbox.TextFrame.TextRange = I
    Next
End Sub
我遇到的问题是,我需要将每个文本框添加到文档的末尾,而不是像现在这样添加到文档的开头。我知道在我给出的示例中,我可以简单地使用
进行I=10到1的步骤-1
。然而,由于我在实际项目中使用了文本框,这是不可能的

我花了几个小时玩代码,但就是没能弄明白。提前感谢您的帮助


Josh.

Joshua,这是最后的工作代码:

Sub InsertInlineTextBox()

' Move all the text after the cursor to a new paragraph
' and jump to the start point of this paragraph
Selection.InsertParagraphAfter
Selection.MoveDown Unit:=wdParagraph, count:=1

Dim aShape As Shape

' Insert the shape at the current cursor position +1 point down in vertical
' direction to prevent automatic moving the shape to the previous paragraph
' during 'inlining'
Set aShape = ActiveDocument.Shapes.AddTextbox( _
    msoTextOrientationHorizontal, _
    Selection.Information(wdHorizontalPositionRelativeToPage), _
    Selection.Information(wdVerticalPositionRelativeToPage) + 1, 400, 60)

With aShape
    .TextFrame.MarginBottom = 0 ' adjust text margins
    .TextFrame.MarginLeft = 0
    .TextFrame.MarginRight = 0
    .TextFrame.MarginTop = 0
    .Line.Visible = msoFalse    ' don't show the border

    ' converting to InlineShape will place
    ' the shape at the start point of paragraph
    .ConvertToInlineShape
End With

' Remove carriege return before the shape
Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
Selection.MoveLeft Unit:=wdCharacter, count:=1
Selection.Delete Unit:=wdCharacter, count:=1
End Sub
我还使用此宏禁用文本框中的拼写检查 因为它们通常包含一组C++示例代码:

Sub NoSpellCheck()
  Selection.Range.SpellingChecked = True
  Selection.Range.NoProofing = True
End Sub

谢谢你的回答-我猜你不在Word 2013上吧?事实上,我问了这个问题,并从那里的人们那里得到了一些建议,这些建议都是针对他们的Word 2010而不是我的2013。请您确认这是事实(即,您的代码在早期版本的word中对您有效)?Joshua,我在今天早上的一些见解之后更新了代码)。是的,这是为Word2013开发的,但Shape和InlineShape对象在2010版本中也可用。呵呵,我似乎仍然无法让它工作。我已经添加了以下代码,以便将数字输入到文本框中(根据原始问题):
对于I=1到10,在子语句之后,
在With语句之后,
在End子语句之后,
在下一个
之后,但我仍然有一个问题,最左上角的文本框是10而不是1。如果这在2013年对您有效,我可以问一下我做错了什么吗?内联总是将文本框放在当前行的开头,因此在进行任何其他操作之前,您需要始终为每个文本框创建新段落,以将其与其他文本隔离,因此我认为您可以:1)创建段落2)在该段落中插入文本框(AddTextbox,ConvertToInlineShape)3)在文本框之后创建一个新段落并插入新文本框重复此过程10次。然后移动到每个新创建的段落末尾,删除carriege return(最后3行代码)。您最终应该可以根据需要订购10个文本框。