将图像移动到图纸上的特定位置



我有12张图片,它们是我直接从windows文件夹拖放到工作表中的。它们被命名为";11.bmp"12.bmp"1 3.bmp";等等我想移动它们,但是怎么移动呢?

这是我正在尝试的代码:

Worksheets("R").Shapes("1 1").Top = Worksheets("R").Rows(24).Top

我不知道他们是怎么提到的。它们与.xlsm文件位于同一文件夹中。我试过

Worksheets("R").Shapes("1 1.bmp").Top = Worksheets("R").Rows(24).Top

也是。

这两个例子都来自另一个关于堆栈溢出的问题。

正确的语法是什么?

/Jens

以下是首先将图片插入Excel,然后调整或调整图片大小的代码。稍后向下或向右移动图片:

'Insert the Picture from the path if its not present already
Set myPict = Thisworkbook.sheets(1).Range("A1:B5").Parent.Pictures.Insert(ThisWorkbook.Path & "" & "mypic.jpg")
'Adjust the Picture location
myPict.Top = .Top
myPict.Width = .Width
myPict.Height = .Height
myPict.Left = .Left
myPict.Placement = xlMoveAndSize
'myPict.LockAspectRatio = msoTriStateMixed
'Change the width of the Picture
myPict.Width = 85
'change the Height of the Picutre
myPict.Height = 85
End With
'Select the Picutre
myPict.Select
'Move down the picture to 3 points. Negative value move up
Selection.ShapeRange.IncrementTop 3

'Move towards right upto 5 points. Negative value moves towards right
Selection.ShapeRange.IncrementLeft 5

试试这个代码:

Option Explicit
Sub ArrangePictures()
Dim sh As Shape, anchor_cell As Range, v_shift As Long
With Worksheets("R")
Set anchor_cell = .Range("B24")             'left top corner for pictures
v_shift = 0                                 'vertical shift for next picture
For Each sh In .Shapes                      'loop over all the shapes in the sheet
If sh.Type = msoPicture Then            'check if the shape is a picture
sh.Top = anchor_cell.Top + v_shift  'move picture (vertical)
sh.Left = anchor_cell.Left          'move picture (horizontal)
v_shift = v_shift + sh.Height       'add vertical shift for next picture
End If
Next
End With
End Sub

相关内容

  • 没有找到相关文章