Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 10-20-2018, 02:06 PM
p45cal's Avatar
p45cal p45cal is offline Vba to insert picture into desired cell with cell size Windows 10 Vba to insert picture into desired cell with cell size Office 2016
Expert
 
Join Date: Apr 2014
Posts: 956
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

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
Vba to insert picture into desired cell with cell size 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
Vba to insert picture into desired cell with cell size 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
Vba to insert picture into desired cell with cell size 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft