2013-07-12 32 views
0

我试图从Word中的所有命令按钮保存一些值,然后删除它们,然后再次将它们添加回来。删除文档中的所有命令按钮并将它们再次添加回来

这是用于印刷目的。

我的问题是如何循环所有命令按钮来保存它们的顶部,左侧,名称和宽度值,然后如何删除它们,然后如何创建带有先前名称,宽度和位置的新按钮。

我知道如何创建数组和什么,我需要弄清楚的是循环通过命令按钮和添加新的命令按钮与旧值的语法。

回答

0

没有测试的代码,但应在以往任何时候需要

删除命令按钮

For Each o In ActiveDocument.InlineShapes  
    If o.OLEFormat.Object.Name = "CommandButtonName" Then 
     'Save all properties of the command button using .Top, .Left, .Width etc 
     o.Delete 
    End If 
Next 

添加命令按钮稍加修改工作(检查http://support.microsoft.com/kb/246299):

'Add a command button to a new document 
    Dim doc As Word.Document 
    Dim shp As Word.InlineShape 
    Set doc = Documents.Add 

    Set shp = doc.Content.InlineShapes.AddOLEControl(ClassType:="Forms.CommandButton.1") 
    shp.OLEFormat.Object.Caption = "Click Here" 
    shp.OLEFormat.Object.Left = 100 
    shp.OLEFormat.Object.Top = 100 
    shp.OLEFormat.Object.Width = 255 
    shp.OLEFormat.Object.Visible = True 
+0

你不应该使用那种循环来删除进程。如果要删除某些类型的所有元素,请始终使用'For I ... Step -1'! –

0

我想通过调整命令按钮到0x0亲提供了一个更优雅的选项,不需要阵列,速度更快。

相关问题