excelperfect 下面的代碼遍歷當(dāng)前工作表中所有圖片,。Sub LoopThroughImages() Dim shp As Shape Dim ws As Worksheet Set ws = ActiveSheet For Each shp In ws.Shapes If shp.Type = msoPicture Then MsgBox shp.Name & '是一幅圖片' End If Next shp End Sub
Sub CheckIfPicture() Dim obj As Object Set obj = Selection If TypeName(obj) = 'Picture' Then MsgBox '所選的是圖片' Else MsgBox '所選的不是圖片' End If End Sub 圖片能夠被鏈接到單元格或者命名區(qū)域,這樣可以使圖片是動(dòng)態(tài)的,,當(dāng)單元格中的內(nèi)容變化時(shí)圖片也隨之變化,。Sub MakeImageLinkedPicture() Dim ws As Worksheet Set ws = ActiveSheet ws.Pictures('Picture 6').Formula = '=C2:E9' End Sub
Sub ImagePlacementAndLocking() Dim myImage As Shape Dim ws As Worksheet Set ws = ActiveSheet Set myImage = ws.Shapes('Picture 6') '圖片放置選項(xiàng) myImage.Placement = xlFreeFloating '鎖定圖片(在工作表保護(hù)時(shí)阻止編輯) myImage.Locked = True End Sub 下面的代碼旋轉(zhuǎn)圖片指定數(shù)。Sub RotateImageIncremental() Dim myImage As Shape Dim rotationValue As Integer Set myImage = ActiveSheet.Shapes('Picture 6') rotationValue = 45 myImage.IncrementRotation (rotationValue) End Sub
Sub RotateImageAbsolute() Dim myImage As Shape Dim rotationValue As Integer Set myImage = ActiveSheet.Shapes('Picture 6') rotationValue = 120 myImage.Rotation = rotationValue End Sub
|