VBA Picture Copy&Paste

set myshapes=.worksheets(1).shapes(“1”)

myshapes.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ThisWorkbook.Worksheets("Sheet3").Paste Destination:=ThisWorkbook.Worksheets("Sheet3").Cells(s, c)

``

Sub pictureCV()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim FileName$, Path$, AK As Workbook
Dim ShtName$ ,pictureID$  'band$, col$
Dim wb As Workbook

Arr1 = ThisWorkbook.Worksheets("Sheet1").Range("D12:D" & 12 + bm)
Arr2 = ThisWorkbook.Worksheets("Sheet1").Range("H13:H" & 13 + cm)
Arr3 = ThisWorkbook.Worksheets("Sheet1").Range("E13:E19")
'Arr1 = Array("*band_1", "*band_2", "*band_3", "*band_4", "*band_6", "*band_7", "*band_9", "*band_10")
'Arr2 = Array("_TW.csv", "_TR.csv", "_TG.csv", "_TB.csv")
s = 3
Path = ThisWorkbook.Path + "\"  

FileName = Dir(Path & "*.xlsx")
c = 2
Do While FileName <> ""
    Set wb = GetObject(Path & FileName)
    ThisWorkbook.Worksheets("Sheet3").Cells(2, c) = FileName
    
    s = 3
    
    For i = 0 To 6
        ShtName = ThisWorkbook.Worksheets("Sheet1").Range("E" & 13 + i)
        With wb.Worksheets(ShtName)
            pictureID= ThisWorkbook.Worksheets("Sheet1").Range("B13" )
            'For Each myshapes In .Shapes
            Set myshapes = .Shapes(pictureID)
            'ThisWorkbook.Worksheets("Sheet3").Cells(s, 2) = myshapes.Name
            ThisWorkbook.Worksheets("Sheet3").Cells(s, c) = ShtName
            '.Shapes(myshapes.Name).Copy
            myshapes.Copy
             myshapes.CopyPicture Appearance:=xlScreen, Format:=xlPicture
             'ThisWorkbook.Worksheets("Sheet3").Cells(s, c).Select
            ThisWorkbook.Worksheets("Sheet3").Paste _
            Destination:=ThisWorkbook.Worksheets("Sheet3").Cells(s, c)
             
            
            s = s + 30
            
            'Next

        End With
        
    Next
    wb.Close False
    FileName = Dir

    c = c + 14
Loop



Application.ScreenUpdating = True
Application.DisplayAlerts = True


End Sub
Sub Export4() ''選區中各圖片按粘貼首圖位置對應粘貼
    Sheets("圖片").Activate
    Dim rng As Range, cel As Range, m&, n&, r&, c&, p As Shape
    Dim ar(), br(), rh#, cw#
    For Each p In ActiveSheet.Shapes ''這一循環是刪除原粘貼的圖片(不刪除時,這循環不用)
        p.Cut
    Next
    For Each cel In Sheets("原圖").Range("b2:c3")
        rh = cel.RowHeight
        cw = cel.ColumnWidth
        m = m + 1
        If m = 1 Then: r = cel.Row: c = cel.Column
        ReDim Preserve ar(1 To m)
        ReDim Preserve br(1 To m)
        ar(m) = cel.Row - r
        br(m) = cel.Column - c
        cel.CopyPicture Appearance:=xlScreen, Format:=xlPicture
        If m = 1 Then
            Set rng = Application.InputBox("請選擇單元格", "系統提示!", Type:=8)
            rng.Select
        Else
            rng.Offset(ar(m), br(m)).Select
        End If
        Selection.RowHeight = rh
        Selection.ColumnWidth = cw
        ActiveSheet.Paste
    Next
End Sub

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章