Our Recommendation for You Search your Query, You can find easily. for example search by book name or course name or any other which is related to your education

Followers

Insert image from folder to selected cell and resize image

Adding an image to an Excel cell and automatically adjust the size of the cell (merged cell)

In this tutorial, I will show how we can insert an image into a selected cell (merged cell) from a folder on our hard drive. This insert images from a folder in a specific cell is performed using a VBA macro attached to this tutorial.

I would like to mention that this VBA macro attached, inserting a picture in a selected cell consisting of two merged cells in a way to adjust the image height merged Excel cells and the width is automatically adjusted. For example: If one and the same image are put into the three cells of different heights (Row High) image will either reduce or increase to adjust the height of the selected cells.

In the picture below you see the situation and the cells in which we need to display, add or import images from a folder with our hard drive that we choose through the dialog 'Select image to insert' after running VBA macros. You notice that the three cells of different sizes, these cells are were merged.

Thus we have the following merged cell B3='B3:C3' ; B5='B5:C5' ; B7='B7:E7'. In these cells we need to add images that will select the folders on the disc. Each added (inserted) image will be adjusted to the size of the cells that are selected by before launching a VBA macro.

Inserting image from a folder in a selected merged cells

Insert picture from folder to a selected cell via VBA


This complete VBA macro below You copy it into 'Sheet Module' your Workbook (You must, be sure to save the workbook '*.xlsm' or '*.xls' format.
Create Button to Insert ie. Launch VBA macro (or run through ALT+F8) on the same worksheet (the active worksheet) and try to insert images from a folder on your hard drive.

Sub InsertImageFromFolder()
Dim myPicture As String, myRange As Range 'set of variables for the image and a selected cell
'defining image formats for import

myPicture = Application.GetOpenFilename _
("Pictures (.gif; .jpg; .bmp; .tif),.gif; .jpg; .bmp; .tif", _
, "Choose image for insert")
Set myRange = Selection 'defining the selected cells
'Set myRange = Application.InputBox("Select your range...", Type:=8) 'message to select the destination cell - option
InsertAndSizePic myRange, myPicture 'calling the procedure for resizing images
End Sub
'procedure to insert a picture and adjust the size of the destination cell
Sub InsertAndSizePic(Target As Range, PicPath As String)
Dim p As Picture
Application.ScreenUpdating = False
Set p = ActiveSheet.Pictures.Insert(PicPath)
If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
With Target
p.Top = .Top
p.Left = .Left
p.Width = .Width
p.Height = .Height
End With
End Sub


After copying the VBA macros and create a button to run the same, let's try the functioning of the VBA macro. (the inspiration for the tutorial and VBA source code: mrexcel.com)

Inserting image or picture from folder to a selected Excel cell

 - Select the cell B3
 - Click on the button to run a VBA macro or use the shortcut ALT+F8
 - The newly opened dialog box, locate the folder where the select image
 - Click on the OK button
 - Now to the previously selected cell, you should have inserted an image that fit the size or dimensions of the selected cell. So in some cells of the image is reduced in some cells of the image is increased.
 - All this repeat for each additional Excel cell

 In my case, it looks like the image below, you notice that the picture of the Croatian flag accommodates the dimensions and size of each cell and its real dimensions are 50x33 pix.


How to insert or add a picture from a folder or folders in a single cell or merged cells in Excel to make the image fit the size of the cell