Help! Need macro to insert pics, resize and then fit into particular cell

MISS_AJAZ

New Member
Joined
Jun 23, 2014
Messages
17
Hi all,

I currently have no starting point so need someone to help me from scratch :-)

I need a macro to do the following:

- Open 'Insert picture dialog box'
- After user has selected the pics they would like inserting, then for the macro to insert them into a particular section of cells and then re-size the pictures to fit the cells.

I want the macro to allow any amount of images to be inserted, and also for it to recognize when the cell is full, incase the user wants to insert more pics (press the insert pictures box more than once), I want it to automatically find the next free cell in that section. Hope that makes sense.

Many thanks
Nisha
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi all,

I currently have no starting point so need someone to help me from scratch :-)

I need a macro to do the following:

- Open 'Insert picture dialog box'
- After user has selected the pics they would like inserting, then for the macro to insert them into a particular section of cells and then re-size the pictures to fit the cells.

I want the macro to allow any amount of images to be inserted, and also for it to recognize when the cell is full, incase the user wants to insert more pics (press the insert pictures box more than once), I want it to automatically find the next free cell in that section. Hope that makes sense.

Many thanks
Nisha

What you are asking for will take some time to get right, especially since you don't have any code to start with. I did a quick search to get you started and found some code that brings up the dialog box to choose a picture then asks which cell to put it in. To resize the picture you should just record a macro of you resizing to the correct size then try to insert that code into this one.

Code:
Sub Insert_Pict()
Dim Pict
Dim ImgFileFormat As String
Dim PictCell As Range
Dim Ans As Integer


ImgFileFormat = "Image Files (*.bmp),others, tif (*.tif),*.tif, jpg (*.jpg),*.jpg"


GetPict:
Pict = Application.GetOpenFilename(ImgFileFormat)
'Note you can load in any nearly file format
If Pict = False Then End


Ans = MsgBox("Open : " & Pict, vbYesNo, "Insert Picture")
If Ans = vbNo Then GoTo GetPict


'Now paste to userselected cell
GetCell:
Set PictCell = Application.InputBox("Select the cell to insert into", Type:=8)
If PictCell.Count > 1 Then MsgBox "Select ONE cell only": GoTo GetCell
PictCell.Select
ActiveSheet.Pictures.Insert(Pict).Select




End Sub

You should be able to create an button in your workbook to initiate this macro.

This is not my personal code, but I have tried it and it seemed to work for me.

Good luck and if you run into any other bumps you should post your code again with your question. That should help you get more replies. :)
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,077
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top