What's wrong with the code?

secoo140

Board Regular
Joined
Oct 12, 2013
Messages
85
Office Version
  1. 2010
Platform
  1. Windows
What's wrong with the code?

I keep the image files with the correct names in the folder named "picture" under the folder where the workbook is located. but the choice doesn't work.

Your suggestions?

VBA Code:
Private Sub LB5_Change()

Sheets("Kimlik").Range("I9") = LB5.Value

Dim ad As String
Dim ResimYolu As String
Dim Resim As Object
Dim Foto As Object

Dim ResimAlani As Range

Set ResimAlani = Sheets("Kimlik").Range("I33")

On Error Resume Next
Application.ScreenUpdating = False
For Each Foto In ActiveSheet.Pictures
    If Not Intersect(Foto.TopLeftCell, ResimAlani) Is Nothing Then
        Foto.Delete
    End If
Next

Set ResimAlani = Nothing

ad = LB5.Value

ResimYolu = ActiveWorkbook.path & "\Resim\" & ad & ".png"

ResimEkle (ResimYolu)
    
End Sub


Sub ResimEkle(dosya As String)

If Dir(dosya) = "" Then Exit Sub

With Sheets("Kimlik").Pictures.Insert(dosya)
.Left = Cells(33, 9).Left
.Top = Cells(33, 9).Top
.ShapeRange.LockAspectRatio = True

End With
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What choice doesn't work?

BTW, you turn off the screenupdating but doesn't turn it back on. Maybe that's the problem you are experiencing.
 
Upvote 0
Also, you turn off runtime errors at the beginning
VBA Code:
On Error Resume Next
and never turn them back on again. That is hurting your ability to understand why your code is not working.
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

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