Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-20-2018, 10:44 AM
mbasith mbasith is offline Vba to insert picture into desired cell with cell size Windows 8 Vba to insert picture into desired cell with cell size Office 2010 64bit
Novice
Vba to insert picture into desired cell with cell size
 
Join Date: Oct 2018
Posts: 5
mbasith is on a distinguished road
Default Vba to insert picture into desired cell with cell size

Hi Guys,



This VBA import the picture in the original size into the sheet when selecting the picture and run the vba it is pasting cell size picture in the first A column but not in the active cell where i keep my cursor.. I want the picture to be resized into the desired cell.

Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.Top
.Left = .TopLeftCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub
'Step 4: Press the F5 key to run this macro.
'Step 5: Repeat the steps above to resize other pictures to fit single cell.
 

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 12:44 PM.


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