Macro gives an error: Run-time error 1004. Method Run of object Application failed.

ttt480

New Member
Joined
Jan 25, 2019
Messages
6
Hello friends.

Macro gives an error:
Run-time error 1004. Method Run of object _Application failed.

How to fix this error ?

HTML:
Sub Macro1()
Dim arr As Collection, x, t, i
Set arr = New Collection
For Each x In Range(Cells(6, 17), Cells(Rows.Count, 17).End(xlUp))
arr.Add x.Value
arr.Add ActiveSheet.Cells(x.Row, 9 + x.Column)
Next x
    'arr = Range(Cells(6, 17), Cells(Rows.Count, 17).End(xlUp)).Value
        For i = 1 To arr.Count
            If Not IsEmpty(arr(i)) Then
                If i / 2 = Int(i / 2) Then Macr = "J" & (5 + i) Else Macr = "S" & (5 + i)
                Application.Run arr.Item(i)
                t = Now + TimeValue("0:00:05")
                    Do
                        DoEvents
                    Loop While t > Now
            End If
        Next i
Set arr = Nothing
End Sub

The error highlights the line :
Application.Run arr.Item(i)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
stepping through with F8 does it break on the 1st loop or many.
1004 indicates something is missing.
what is the value of arr.Item(i) when you hover over it as you step through
 
Upvote 0
adding
on error resume next
to the beginning of that sub generates the error with

Set shpHost = ActiveSheet.Shapes("Rectangle 5")
Set shp = ActiveSheet.Shapes.AddPicture(Range(Macr), False, True, -1, -1, -1, -1)
 
Upvote 0
mole999, It's not working.

Now the script just ignores the presence of"macro 4".
(The idea is that the script should execute all macros listed in the table.)

Code:
Sub Macro4()
    Dim shpHost As Shape, shp As Shape
    Dim var
    
    Application.ScreenUpdating = False
    On Error Resume Next
    ActiveSheet.Shapes("Added").Delete
    On Error GoTo 0
    
   On Error Resume Next
    Set shpHost = ActiveSheet.Shapes("Rectangle 5")
     Set shp = ActiveSheet.Shapes.AddPicture(Range(Macr), False, True, -1, -1, -1, -1)
     shp.Name = "Added"
    shp.LockAspectRatio = True
    If shp.Width > shp.Height Then
        shp.Height = shpHost.Height
        shp.Top = shpHost.Top
        var = shpHost.Left + shpHost.Width / 2
        shp.Left = var - shp.Width / 2
    Else
        shp.Width = shpHost.Width
        shp.Left = shpHost.Left
        var = shpHost.Top + shpHost.Height / 2
        shp.Top = var - shp.Height / 2
    End If
    shp.ZOrder msoSendToBack
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I suggested that should go in the first module. it is already in macro4 anyway
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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