vba 写一段代码在Visual Basic中用ms word改变图片的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18492347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:01:02  来源:igfitidea点击:

Writing a code to change the position of a image in Visual Basic in ms word

vbams-wordword-vba

提问by Sumit

As ms word does not allow to record a macro to change the position of a already-inserted & selected image I need to write a macro in visual basic.

由于 ms word 不允许录制宏来更改已插入和选定图像的位置,因此我需要在 Visual Basic 中编写一个宏。

It needs to do the following: 1. Give the selected pic a border 2. Change its position to the lower end of the page.

它需要执行以下操作: 1. 为所选图片添加边框 2. 将其位置更改为页面的下端。

采纳答案by Kazimierz Jawor

If there is only one InlineShapein document (ActiveDocument) the following code can solve your both needs:

如果InlineShape文档 ( ActiveDocument) 中只有一个,则以下代码可以解决您的两个需求:

Sub qSolved()

    With ActiveDocument.InlineShapes(1)
        'border
        .Line.Weight = xlThin
        'conversion to Shape
        .ConvertToShape
    End With

    'bonus :) -if you need to set position of newly created Shape
    With ActiveDocument.Shapes(1)
        .Top = 100
        .Left = 100
    End With
End Sub