+ -
当前位置:首页 → 问答吧 → 如何用VBA移动一个文本框?找了好多天了!

如何用VBA移动一个文本框?找了好多天了!

时间:2011-02-26

来源:互联网

问题:如何移动一个文本框到任意页?
描述:页面是动态的,文本框里的内容是“作者  年 月 日”,只希望文本框出现在最后一页的右下角。
思考:
我试了以下几种方法:
一、找到shape以后剪切,用goto到最后一页,再paste粘贴,但shape没有cut方法。此法不行!
二、找到shape以后设置其left及top,但是只能在第1页变换位置,不能移动到末页。!
三、找到shape的锚点(Anchor),再设法移动Anchor的位置,因为用鼠标操作的话,拖动锚点,文本框也随之移动,但VBA中无表示Anchor的对象,无法操作。此法仍然不行!
请教大家,如何实现呢?

作者: bluecoat   发布时间: 2011-02-26

引用:
原帖由 bluecoat 于 2011-2-26 11:28 发表
问题:如何移动一个文本框到任意页?
描述:页面是动态的,文本框里的内容是“作者  年 月 日”,只希望文本框出现在最后一页的右下角。
思考:
我试了以下几种方法:
一、找到shape以后剪切,用goto到最后一页, ...
Sub Example()
    Dim myShape As Shape
    Dim myRange As Range
    Dim sngWidth As Single
    Dim sngHeight As Single
    Dim newShape As Shape
    Application.ScreenUpdating = False
    With ActiveDocument
        Set myShape = .Shapes(1)
        With myShape
            sngWidth = .Width
            sngHeight = .Height
        End With
        Set myRange = .Paragraphs.Last.Range
        Set newShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, sngWidth, sngHeight, myRange)
    End With
    With newShape
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
        .RelativeVerticalPosition = wdRelativeVerticalPositionMargin
        .Left = wdShapeRight
        .Top = wdShapeBottom
        .TextFrame.TextRange.FormattedText = myShape.TextFrame.TextRange.FormattedText
        .TextFrame.TextRange.Paragraphs.Last.Range.Delete
    End With
    myShape.Delete
    Application.ScreenUpdating = True
End Sub

作者: 守柔   发布时间: 2011-02-26

守柔 版主您好  我现在弄一个代码 代码弄出来了 现在想将这些代码放到word2010的功能区 那样方便使用请你赐教

作者: 蜀郭浪君   发布时间: 2011-02-26

热门下载

更多