VBA 특정 시트부터 특정이미지 반복하여 붙여넣기 및 이미지 모두삭제

2020. 2. 18. 10:00VBA/VBA기초

728x90
반응형

< VBA 이미지 붙여넣기>

Sub 이미지붙여넣기()

    Dim m As Workbook
    Dim ms As Worksheet

    Set m = Workbooks(ThisWorkbook.Name)
    Set ms = m.Sheets("Camera")
  
    Dim sht As Worksheet
    Dim shape As Excel.shape
   
    Dim pic As Picture
    Set pic = ms.Pictures("그림 1")
    
    '시트 반복
    For Each sht In Workbooks(ThisWorkbook.Name).Sheets
    
        ' 조건
        If sht.Index > 4 Then
        
            ' 이미지 복사
            pic.Copy
            
            ' 이미지 붙여넣기
            sht.Paste
            
            For Each shape In sht.Shapes
                Select Case shape.Type
                     Case msoPicture, msoMedia, msoShapeTypeMixed, msoOLEControlObject, msoAutoShape
                           ' 이미지 위치 맞춤
                           shape.Left = 30
                           shape.Top = 30
                     Case Else
                          'Do nothing
                End Select
            Next

        End If
    
    Next

End Sub



< VBA 이미지 모두삭제>

Sub 이미지모두삭제()

    Dim shape As Excel.shape
    Dim sht As Worksheet

    '시트 반복
    For Each sht In Workbooks(ThisWorkbook.Name).Sheets
    
        ' 조건
        If sht.Index > 4 Then

            Debug.Print sht.Name

            '그림

            For Each shape In sht.Shapes

                    Select Case shape.Type

                         Case msoPicture, msoMedia, msoShapeTypeMixed, msoOLEControlObject, msoAutoShape

                               shape.Delete

                         Case Else

                              'Do nothing

                    End Select

            Next

        End If

    Next


End Sub

 

728x90
반응형