W3Ask













HOME  >  SOFTWARE  >  EXCEL

Excel macro to insert a picture with Redime



You want to save a macro that will allow you to insert a picture (located in a directory of your hard drive disk) in an active cell where you will be. This picture should be resized automatically to the size of the initial cell.

But also that it follows the height of the celle and of the column if you modify the width of the column and lines.

In that matter, you won’t have to do it manually again for every picture at every change you do with the height and the width of your columns.

Here is a macro that will do the job :

Public Sub inset_picture()
Dim ficimg As Variant
ficimg = Application.GetOpenFilename(".jpg,*.jpg", , "Choose the picture") ' choice of the file name
ActiveSheet.Pictures.Insert(ficimg).Select ' insertion
With Selection.ShapeRange
.LockAspectRatio = False ' original proportions when you resize
.Top = ActiveCell.Top ' cell height
.Left = ActiveCell.Left ' left of the cell
.Height = ActiveCell.RowHeight ' height of the cell
.Width = ActiveCell.Width ' width of the cell
End With
With Selection
.PrintObject = True ' the object is printed at the same time of the document
.Placement = xlMoveAndSize ' way that the object is linked to the cellesmanière dont l'objet est lié aux cellules
End With
End Sub

Note: Commissions may be earned from the links above.


This page contains references to products from one or more of our advertisers. We may receive compensation when you click on links to those products. For an explanation of our advertising policy, please visit this page.









Related posts:


How to add lines with a VBA code in Excel
https://w3ask.com/how-add-lines-vba-code-excel/
If you want to automatically add line in your Excel sheet, you can use a VBA code. The following example will add lines after the N column in ...
How to convert a number in time with Excel ?
https://w3ask.com/convert-number-in-time-excel/
When we enter a date with points, is there a possibility to convert it automatically into a date with slashes, so that it could be taken into ...
How to get the maximum value in Excel
https://w3ask.com/maximum-value-in-excel/
We have two column, A and B, with towns in A and numbers in B. We would like to determine the maximum value in B, the city with the biggest ...
Choice of a list with a condition in Excel
https://w3ask.com/choice-list-condition-excel/
There are two sheets, in which there is two colums : – from A1 to A3 with dates (example : 01/01/2016), – from B1 to B3 with titles ...
Excel VBA, test of the And (&)
https://w3ask.com/excel-vba-test-of-the-and/
In an Excel VBA, how to detect a cell with a & character in a For loop ? You don’t necessarily need a loop in that case, here is an example ...












Languages

  • English
  • French
  • German
  • Italian
  • Dutch
  • Portuguese
  • Spanish

Know us

  • About
  • Contact
  • Categories list

Privacy

  • Privacy & Cookie Policy
  • Advertising policy
W3Ask © 2023. All rights reserved.
Disclaimer:

When you click on links to various merchants on this site and make a purchase, this can result in this site earning a commission. Affiliate programs and affiliations include, but are not limited to, the eBay Partner Network.

As an Amazon Associate I earn from qualifying purchases.

This page includes affiliate links for which the administrator of W3Ask may earn a commission at no extra cost to you should you make a purchase. These links are indicated using the hashtag #ad.


Information:

We do not assume any responsibility for the data displayed on our website. Please use at your own risk. Some or all of this data may be out of date or incomplete, please refer to the technical page on the respective manufacturer's website to find the latest up-to-date information regarding the specifics of a product.


Trading System Forex GadgetVersus GadgetVersus France