[英]MS-Word VBA reference identification
I have a custom content control in Microsoft Word from a third party I am trying to resize the width and height of. 我试图从第三方调整宽度和高度的大小时,在Microsoft Word中有一个自定义内容控件。 Normal content control selection via VBA is not working because this control has no Title or Tag. 通过VBA进行的常规内容控件选择无效,因为该控件没有标题或标签。 However, if I manually select the object and resize it programmatically using "Selection.ShapeRange.Height = x" or ShapeRange.Width it does work. 但是,如果我手动选择对象并使用“ Selection.ShapeRange.Height = x”或ShapeRange.Width以编程方式调整其大小,则它确实可以工作。 So to do it all programmatically I need to determine the name of the "selection" without having to manually select it. 因此,要以编程方式完成所有操作,我需要确定“选择”的名称,而不必手动选择它。
Is there a way to "inspect" the complete reference to the currently selected object in word, so we can then get a starting point to work with it in VBA? 有没有一种方法可以“检查”对当前所选对象的完整引用,因此我们可以在VBA中获得一个使用它的起点?
It's hard to know what type of object your dealing with. 很难知道您要处理的对象类型。 I tested this by inserting a blank ActiveX image control, selecting it and then running the macro. 我通过插入空白的ActiveX图像控件,选择它并运行宏来进行了测试。 The code has two methods but one is commented out. 该代码有两种方法,但其中一种已被注释掉。
Sub FindName()
MsgBox (Selection.Fields.Item(1).OLEFormat.ClassType)
'MsgBox (Selection.InlineShapes.Item(1).OLEFormat.ClassType)
MsgBox (Selection.InlineShapes.Item(1).Field.Index)
MsgBox (Selection.InlineShapes.Item(1).AlternativeText)
'Show current name
MsgBox (Selection.Fields.Item(1).OLEFormat.Object.Name)
'Set new name
Selection.Fields.Item(1).OLEFormat.Object.Name = "Image5"
'Re-display name to show that it changed
MsgBox (Selection.Fields.Item(1).OLEFormat.Object.Name)
End Sub
The result was this: 结果是这样的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.