1

我对下面的代码有疑问。我写了一个宏来复制和粘贴一系列行的图片,当我单步执行它时它就可以工作。但是,当我运行宏时,它往往会卡在一个随机粘贴上(通常不是单个粘贴。请建议如何更好地编写此代码以避免在运行宏时出现此问题

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
4

0 回答 0