ActiveSheet.Cells(1, 1).Select ActiveSheet.Pictures.Insert( _ "D:\My Documents\My Pictures\6cf0492712220dc1f03f5b.jpg").Select With Selection.ShapeRange '裁剪 .PictureFormat.CropTop = 30 '下移裁剪 .PictureFormat.CropLeft = 30 '右移裁剪 .PictureFormat.CropBottom = 30 '上移裁剪 .PictureFormat.CropRight = 30 '左移裁剪 '裁剪 '移動旋轉 通常移動距離都是和裁剪相對應的,這樣圖才能在指定單元格的位置。 .IncrementLeft -30 '相對圖片初始位置水平移動正數向右,負數向左 .IncrementTop -30 '相對圖片初始位置垂直移動正數向下,負數向上 .IncrementRotation 0 '相對圖片初始位置中心旋轉 '移動旋轉 '大小 .LockAspectRatio = msoFalse '圖片縱橫比鎖定為msoTrue,高度和寬度調一個值整個圖就會變 .Height = 200 ' 高度 .Width = 150 '寬度 '大小 End With
ActiveSheet.Cells(3, 1).Select '選擇要插入圖片的單元格,定位 i = "D:\My Documents\My Pictures\111.gif" '圖片地址可以寫入變量 ActiveSheet.Pictures.Insert(i).Select '用變量插圖片 Cells(1, 1) = Selection.Name '在第一個單元格返回插入圖片對象的名稱,方便以后的操作 Application.CommandBars("Picture").Visible = False '隱藏圖片編輯工具 ActiveSheet.Shapes(Cells(1, 1)).Select '選擇第一個單元格里所留的那個名稱的圖片對象 Selection.Delete '刪除選擇的圖片對象 刪除全部圖片的一種方法 Dim Sh As Shape '定義一個圖形的變量 For Each Sh In ActiveSheet.Shapes '遍游活動表里的所有圖形組件 If Sh.Name Like "Picture *" Then '如果圖形對象的名稱里有“Picture *”通配的往下執行,因為圖片對象默認對象名稱是Picture 數字 Sh.Select '選擇圖片名稱的對象 Selection.Delete '刪除圖片對象 End If Next Sh '利用循環就把圖片對象都給刪除了。