InsertPicture into Excel with a macro

smintonuk

New Member
Joined
Nov 1, 2005
Messages
2
Hi
I am attempting to do a bulk insert of thumbnail images (30 of them) into a workbook. I have the specific filepath to the individual images specified in column B and I want to automate the insertion of the images into column A.

I have found the a template for a code that suggests that it will perform the insertion, but I cannot modify the code to fit my specific situation becuase I am a novice at VBA and I need help!.

My images are all in a folder called: C:\Program Files\WebSundew\rightmove\images

Here is the code that I am trying to manipulate: What variables in the code do I have to change to get this to fit my situation?


Sub TestInsertPictureInRange()
InsertPictureInRange "C:\FolderName\PictureFileName.gif", _
Range("B5:D10")
End Sub

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub


Any help would be graeatly appreiciated.

Thanks

smintonuk
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Insert Picture overrides my data

Thanks for the suggestion. I was able to get the macro to work, but it would not import my images in sequence. It would only insert the 1st image, but it would insert it multiple times. My images are labeled: Image01, Image02, Image03 etc. some are .gifs, some are .jpgs.

The macro that you suggested also overwrites my data, and I was hoping to get the images inserted into the corresponding rows next to the filepath column.

Thanks for you help so far

Smintonuk
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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