S
Sam Kuo
Below is my VBA script to dynamically insert and size an image to a merged
cell.
My questions are, can I:
- scale the image to maximum inside a merged cell, while keeping its
original height to width ratio (instead of distorting the image scale to the
full merge cell size as it does now)?
- change the caption of the command button to "edit image" if an image has
been inserted, and change back to "insert image" if nothing is inserted?
Any help would be appreciated
-------------------------------------------------
Private Sub CommandButton_Click()
Dim ImageCell As Range
Set ImageCell = Sheet3.Range("B10").MergeArea
' Go to "screen dump" input merged cell (B10:AK30)
ImageCell.Select
' Open "Insert Picture" pop-up window
Application.Dialogs(xlDialogInsertPicture).Show
' Quite action if nothing is selected
On Error Resume Next
' Otherwise size the image selection to full merged cell size
With Selection
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
.Placement = xlMoveAndSize
End With
End Sub
cell.
My questions are, can I:
- scale the image to maximum inside a merged cell, while keeping its
original height to width ratio (instead of distorting the image scale to the
full merge cell size as it does now)?
- change the caption of the command button to "edit image" if an image has
been inserted, and change back to "insert image" if nothing is inserted?
Any help would be appreciated
-------------------------------------------------
Private Sub CommandButton_Click()
Dim ImageCell As Range
Set ImageCell = Sheet3.Range("B10").MergeArea
' Go to "screen dump" input merged cell (B10:AK30)
ImageCell.Select
' Open "Insert Picture" pop-up window
Application.Dialogs(xlDialogInsertPicture).Show
' Quite action if nothing is selected
On Error Resume Next
' Otherwise size the image selection to full merged cell size
With Selection
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = ImageCell.Width
.Height = ImageCell.Height
.Placement = xlMoveAndSize
End With
End Sub