#1
|
|||
|
|||
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. |
#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 |
#3
|
||||
|
||||
Hi and welcome
Please,do not crosspost your question on multiple forums without including links here to the other threads on other forums. Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post. Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site). If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question Do not post any further responses in this thread until a link has been provided to these cross posts.
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#4
|
|||
|
|||
Thank you so much...
p45cal,Thanks a lot buddy
REally appreciate your response... |
#5
|
||||
|
||||
In light of your attitude at: https://www.excelforum.com/excel-pro...ml#post4995451
I am closing this thread too. Kindly adjust your attitude or stay away from all such forums and save yourself the grief of being taken to task.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
vba to insert picture |
Thread Tools | |
Display Modes | |
|
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 |