VBA code to insert multiple pictures

mulatsih

New Member
Joined
Aug 20, 2011
Messages
4
Hi,

I want to insert several pictures in an excel sheet.
The complete name with path and extension of the pictures are in column K.
The Cellposition of where to insert the pictue is in an array,(A10,H10,A50,etc.).

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this. File names start in K1.
Code:
Sub IP()

    Dim position As Variant
    Dim i As Integer
    
    position = Array("A10", "H10", "D15", "B20")
    
    For i = 0 To UBound(position)
        Range(position(i)).Select
        Pictures.Insert Cells(i + 1, "K").Value
    Next
    
End Sub
 
Upvote 0
Hi John,

Thanks for the reply.
I get the failure object required at this line: Pictures.Insert Cells(i + 11, "K").Value.

Any ideas what could be the problem.

Thanx.
 
Upvote 0
That line isn't the same as the code I posted. My code expects the picture file names to be in K1, K2, K3, etc, but your code implies they start in K11. Which cells in column K contain your file names?

Please post your whole code, or enough of it to reproduce the error.
 
Upvote 0
Hi John,

You were right, it's working now.

I have another problem:I want to paste the textbox33 16 rows down from the reference cell B12. It's working till the last line. Any ideas?

Dim i, n As Integer
Dim position As Variant

n = TextBox34.Value - 2
position = Array("B12", "Q12", "B33", "Q33")
Sheets("Foto").Activate
Range(position(n)).Select

ActiveCell.Offset(16, 0).Select
ActiveCell.Value = TextBox33.Paste
 
Upvote 0
Hi John

Thanks again, works again!

I have another bug in this one:

Private Sub TextBox30_Change()
If TextBox30 > 0 And TextBox30 <> "" Then
Dim x, y As Variant
Dim varmjb As String
Set Rangedimensie1 = Workbooks("Werkmap3.xls").Worksheets("werkmap").Range("$C$2:$W$1000")
varmjb = Application.VLookup(Onderdeel, Rangedimensie1, (20), False)
TextBox29 = varmjb
y = Application.Substitute(varmjb, "x", TextBox16.Value)
y = Evaluate(y)
TextBox28.Value = Application.Round((Aantal.Value * y), 1) / 1000
Else: TextBox28.Value = ""
End If
End Sub

The textbox28.value is written as text so I need to covert it in excel to number. Can you tell how to do this in the above sub?

Thanx.
 
Upvote 0
I'm not sure what you mean. Doesn't this line:
Code:
TextBox28.Value = Application.Round((Aantal.Value * y), 1) / 1000
already produce a number in TextBox28, for example 1234.5678, which you can use in Excel?

Do you mean like this?
Code:
Dim tb28 As Double
tb28 = TextBox28.Value
'or
tb28 = CDbl(TextBox28.Value)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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