这就是我插入图片的方式:格式化,剪切,将其粘贴到正确的单元格中,然后通过.top和.left抓取它。我这样做是为了让图片在排序时与行一起移动(如果我只是.addpicture它不会被排序)。
...但是现在我已经解决了排序问题,.ClearComments开始删除图片而不是评论。 (它也会删除评论,但它会先删除图片!)
关于如何解决这个问题的任何想法?
Dim myPicture as Picture
Dim pictShape as Shape
Dim oCell as Range
Set myPicture = ActiveSheet.Pictures.Insert("http://img.youtube.com/vi/" & VideoURL & "/default.jpg")
With myPicture
.ShapeRange.PictureFormat.CropTop = 7.96
.ShapeRange.PictureFormat.CropBottom = 8.225
.ShapeRange.LockAspectRatio = msoTrue
.Height = pixHeight
.Top = pixTop
.Left = pixLeft
End With
Set pictShape = ActiveSheet.Shapes(myPicture.Name)
pictShape.Cut
oCell.PasteSpecial
For Each Sh In ActiveSheet.Shapes
If Sh.Top = pixTop And Sh.Left = pixLeft Then 'found it!
Sh.Name = "Picture " & i
Exit For
End If
Next Sh
Set pictShape = ActiveSheet.Shapes("Picture " & i)
With pictShape
.Top = pixTop
.Left = pixTop
End With
答案 0 :(得分:1)
解决。在计划使用时,不要在形状上使用.PasteSpecial.ClearComments,而是使用.Paste。
Set ExcSel = Selection ' save previous selection
oCell.Select ' select cell to paste to
ActiveSheet.Paste ' paste
ExcSel.Select ' select the originaly selected cell