我有一個包含檔案路徑的表,當單擊按鈕時,宏將根據 url 路徑顯示影像。這是我的代碼(來源:
但我希望影像在所有合并的單元格中。如下圖所示

如果您看到任何可以解決此問題的方法,請告訴我!我敢肯定這很簡單,但我已經在這個問題上停留了一段時間。
uj5u.com熱心網友回復:
您可以使用MergeAreaRange 物件的屬性來回傳合并的范圍。您的宏可以修改如下(未經測驗)。. .
Sub Macro_1()
Dim cShape As Shape
Dim cRange As Range
Dim cColumn As Long
On Error Resume Next
Application.ScreenUpdating = False
Set xRange = ActiveSheet.Range("C5, G5, C8, G8")
For Each cell In xRange
cName = cell
ActiveSheet.Pictures.Insert(cName).Select
Set cShape = Selection.ShapeRange.Item(1)
If cShape Is Nothing Then GoTo line22
cColumn = cell.Column
Set cRange = cell.MergeArea
With cShape
.LockAspectRatio = msoFalse
.Height = cRange.Height - 5
.Width = cRange.Width - 5
.Top = cRange.Top 2
.Left = cRange.Left 2
.Placement = xlMoveAndSize
End With
line22:
Set cShape = Nothing
Next
Application.ScreenUpdating = True
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/473962.html
