1

I am having an issue with the code below. I have written a macro to copy and paste pictures of a series of rows, and it works when I step through it. However, when I run the macro, it tends to get stuck on one random paste (usually not a singular one. Please advice how to better write this code to avoid this issue when running the macro

Sub Presentation_Formating()
   Dim wb As Workbook
   Dim pic As Picture
   Dim i As Integer, j As Integer
   Dim content As Worksheet
   Dim presentation As Worksheet

   i = 5
   j = 7

   Set content = Sheets("Recovery Indicator Content")
   Set presentation = Sheets("Recovery Indicator")
   Set wb = ActiveWorkbook

   'Delete all existing pictures besides the photo in the top right
    For Each pic In Sheets("Recovery Indicator").Pictures
        If pic.Name <> "Picture 65" Then
            pic.Delete
        End If
    Next pic
    
    Do Until i > 62
        wb.Sheets("Recovery Indicator Content").Select
        Range(Cells(i, 1), Cells(i + 12, 4)).CopyPicture Appearance:=xlScreen, Format:=xlPicture
        wb.Sheets("Recovery Indicator").Select
        Range(Cells(i + 9, 3), Cells(i + 21, 6)).Select
        ActiveSheet.Paste
        
        i = i + 14
    Loop

    MsgBox ("Done!")
End Sub
GSerg
  • 76,472
  • 17
  • 159
  • 346
DDDDHHHH
  • 11
  • 1
  • https://stackoverflow.com/questions/63924782/requested-object-is-not-available#comment113039319_63924782? – GSerg Sep 17 '20 at 15:19
  • 1
    I've seen this issue before - you can retry the paste and it typically works after a couple of tries: https://stackoverflow.com/questions/60579662/shapes-copy-paste-timing-issue-excel-vba/60582628#60582628 – Tim Williams Sep 17 '20 at 15:24
  • Tim, That worked perfectly!!! Thanks for sharing – DDDDHHHH Sep 17 '20 at 17:52

0 Answers0