• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro Loop not inserting image after 7th Loop

ramma556

New Member
Hi,

I have attached a file. In this file I am getting error (Error is "Application Error 1004") in 8th loop and not able to understand why this is happening.

Till 7th Loop the macro is running perfectly.
I tried to find if image is missing but it is not the case because I cross checked and the image is there. Also tried by changing the image name but it is not running after 7th loop.

Thank you for your kindly help and concern in this.
 

Attachments

  • Test.xlsm
    19.2 KB · Views: 1
It may only cause due to pic issue. To verify the same check this...


Code:
Sub Insert_Picture_2()

Dim ImageName As String, LoopNo As Long

Application.ScreenUpdating = False
With ActiveSheet
    .Pictures.Delete
   
    For LoopNo = 9 To 300 Step 16
        ImageName = .Cells(LoopNo, 7)
           
            If Len(Dir("E:\Images\" & ImageName & ".jpg")) > 0 Then
            'Path where pictures are stored
                .Pictures.Insert("E:\Images\" & ImageName & ".jpg").Name = ImageName
                    With Shapes(ImageName)
                    .Visible = True
                    .Left = .Parent.Cells(LoopNo, 10).Left
                    .Top = .Parent.Cells(LoopNo- 3, 5).Top
                    .Height = 60#
                    .Width = 60#
                    End With
            End If
    Next LoopNo

.Range("B5").Select
End With
Application.ScreenUpdating = True

End Sub
 
Thank you so much.

Yes, you are right. This error was due to pic issue. My path was incorrect and it was referring to some different folder whereas I was looking in some other folder.
 
Back
Top