返回列表 上一主題 發帖

[發問] 選取特定儲存格範圍內的圖形物件的VBA語法

回復 2# jsleee
VBA只能從圖片得到其左上角的儲存格
沒辦法"直接"從儲存格得到對應圖片
所以只能自己寫Function用For去找,例如下面這樣
  1. Function GetPicByCell(from_cell As Range) As Picture
  2.     For Each pic In ActiveSheet.Pictures
  3.         If pic.TopLeftCell.Address = from_cell.Address Then
  4.             Set GetPicByCell = pic
  5.             Exit Function
  6.         End If
  7.     Next
  8.     Set GetPicByCell = Nothing
  9. End Function
複製代碼
  1. Sub Test1()
  2.     Dim pic As Picture
  3.     Set pic = GetPicByCell(Cells(32, 2))
  4.     If pic Is Nothing Then
  5.         MsgBox "找不到圖片"
  6.     Else
  7.         Debug.Print pic.Width, pic.Height
  8.     End If
  9. End Sub
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

        靜思自在 : 多做多得。少做多失。
返回列表 上一主題