Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #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.
  #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: 863
p45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant future
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
  #3  
Old 10-21-2018, 12:24 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Vba to insert picture into desired cell with cell size Windows 7 64bit Vba to insert picture into desired cell with cell size Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,766
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

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  
Old 10-21-2018, 02:39 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
Thumbs up Thank you so much...

p45cal,Thanks a lot buddy

REally appreciate your response...
  #5  
Old 10-21-2018, 03:32 AM
macropod's Avatar
macropod macropod is offline Vba to insert picture into desired cell with cell size Windows 7 64bit Vba to insert picture into desired cell with cell size Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Closed Thread

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
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:48 AM.


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