Importing multiple images using VBA macros

designtime

New Member
Joined
May 25, 2012
Messages
1
Hi all,

Firstly i'm a design student using excel to make a prototype of an interface using excel. My knowledge of VB and macros is next to nothing so please forgive any ignorance on my part. I've managed to bungle several strings of code i've found in forums together to accomplish a desired task, but it seems to be having issues.

I need to import multiple images from a predetermined folder into column A, with each image in a separate cell. I need to do this on multiple sheets. The problem i'm having is that every time i save the document and re-open it, i have to enable the macro option and it seems to repeat the function; re-importing the images onto whatever sheet i have open at the time and overlaying multiple images on top of each other.

Here is the code i used:

Function ShowPic(PicFile As String) As Boolean
Dim AC As Range
On Error GoTo Done
Set AC = Application.Caller
Set p = ActiveSheet.Pictures.Insert(PicFile)
With Application.Caller
t = .Top + 8
l = .Left + 4
w = (.Offset(0, .Columns.Count).Left - .Left) * 0.95
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
End With
Set p = Nothing
'ActiveSheet.Shapes.AddPicture PicFile, True, True, AC.Left, AC.Top, 106, 79
ShowPic = True
Exit Function
Done:
ShowPic = False
End Function

Please help! thanks in advance
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
There must be more code than what you show. You only show the function to add one single picture.

I suspect you have more code in the Workbook_Open event handler (doubleclick the ThisWorkbook item in the VBA editor to check if there is code in there).

The dialog asking you to enable the macro option is due to your security settings. You could set these to Low, but I strongly advise against that! There are a few other possibilities to not have that dialog, but let's get the issue of the code not doing what you want, solved first :)
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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