![]() |
|
#2
|
||||
|
||||
|
The macro you've provided requires the active selection to be a picture. No problem. Just make sure that the active cell before you select the picture and run this tweaked macro is the cell you want the picture to be in.
Code:
Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With ActiveCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = ActiveCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = ActiveCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = ActiveCell.Top
.Left = ActiveCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub
|
| Tags |
| vba to insert picture |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Insert a picture in the footer in a table cell for each section | MaryLouP | Word VBA | 1 | 01-19-2018 03:16 AM |
Clear all cell colors within a range starting at cell A8 and change row of active cell to yellow
|
FUGMAN | Excel Programming | 7 | 02-05-2017 08:37 AM |
If value of cell A Matches a value in a Range of cells (column) then add value of cell A to cell C
|
rick10r | Excel | 1 | 07-05-2016 12:07 PM |
Assign the value of a cell as a cell reference of another cell in Excel 2010 - How to?
|
bharathkumarst | Excel | 7 | 10-13-2014 10:25 AM |
| Insert Picture with standard size | styleruk | Word | 4 | 02-10-2014 09:09 AM |