Macro Error

gottimd

Well-known Member
Joined
Jul 29, 2002
Messages
501
I have the following code that has been working for about a year now and all of the sudden it keeps debugging and saying Run Time Error '1004': Select method of Picture Class failed.

Here is a piece of the code:
Code:
 For Each Sheet In Worksheets
    Sheet.Activate
    For Each Pic In ActiveSheet.Pictures
        Pic.Delete
    Next Pic
    Next Sheet
    
    Sheets("Sheet1").Select
    
    Dim picnme As String
    Dim rng As Range
    Dim i, j As Integer
    Dim Count As Integer
    
    Count = 0
    
    For i = 6 To 106
    j = i + 1
    
    'The count variable will be used to decide whether to perform the actions.
    'It is set up to match your specified pattern.
    Count = Count + 1
    If Count > 8 Then Count = 1
    If Count < 6 Then
        
    'rows 6-10
    
    picnme = Range("U" & i)
    Range("C" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
    
    picnme = Range("U" & i)
    Range("C" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
    
    picnme = Range("U" & i)
    Range("C" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

    picnme = Range("U" & i)
    Range("C" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

    picnme = Range("U" & i)
    Range("C" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

    picnme = Range("V" & i)
    Range("G" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
    
    picnme = Range("V" & i)
    Range("G" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
    
    picnme = Range("V" & i)
    Range("G" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

    picnme = Range("V" & i)
    Range("G" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

    picnme = Range("V" & i)
    Range("G" & j).Select
    ActiveSheet.Pictures.Insert( _
        "C:\Archive\Pictures\" & picnme & ".jpg").Select
    Selection.ShapeRange.IncrementTop -21#
    Selection.ShapeRange.ScaleHeight 0.62, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.72, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft

The Names, properties, cell links are all valid and remain unchanged. All the pictures it is inserting are .jpg, so why this error message?

Thanks for your help in advance.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If you just hit "Debug" when the the error occurs, that should highlight which line is causing the error.

Of course, stepping through the code is a good way to see what is happening at each point along the way. Sometimes knowing which line is causing the error doesn't make sense until you see what happens beofre that line (maybe it can find the object because you aren't on the right sheet, etc).
 
Upvote 0
Yes, it fails at:

ActiveSheet.Pictures.Insert( _
"C:\Archive\Pictures\" & picnme & ".jpg").Select

but the weird thing is, is that it gets to some and inserts them fine. Also, this macro has worked for a long time with no problems. All pictures were inserted fine, no errors. Now all of the sudden it is failing. No picture names have changed, all jpgs.
 
Upvote 0

Forum statistics

Threads
1,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

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