Copying multiple images from one workbook to another as separate images

旧城冷巷雨未停 提交于 2020-01-25 00:51:26

问题


In 2003 the code worked perfectly, we just updated to 2010 and its affecting our outgoing proposals.

I've been looking on multiple sites and everything i have tried gives me all the pictures pasted into one grouped image OR gives me multiple boxes that say image cannot be viewed.

The pictures will always be located in column L, but it can be one picture or 50 and even none. So i need to be able to select all images, copy and open another workbook and paste in a designated column with the same format and as separate images, not as a single image which is what I am getting right now. Any help would be greatly appreciated. Below is the latest code I have tried, still getting a "single grouped image" when pasting.

Windows(ourName2).Activate
Sheets("Sheet5").Select
On Error Resume Next
ActiveSheet.Pictures.Copy
Windows("Proposal.xls").Activate
Sheets("Sheet2").Select
ActiveSheet.PasteSpecial Range("L7")

Update, attempting to use this code raises error on the line Set wbSource = Workbooks("ourName2")

Dim wbSource As Workbook 
Dim wbDest As Workbook 
Dim shSource As Worksheet 
Dim shDest As Worksheet 
Dim shp As Shape 

Set wbSource = Workbooks("ourName2") 'modify as needed   
Set wbDest = Workbooks("MPlanner.xls") 'modify as needed 
Set shSource = wbSource.Sheets("Sheet5") 'modify as needed 
Set shDest = wbDest.Sheets("MAudit") 'modify as needed 

shSource.Pictures.Copy shDest.Range("L7").Paste

回答1:


This worked for me:

Sub test()
    ActiveSheet.Pictures.Copy
    With Workbooks("temp.xls").Sheets("Sheet1")
        .Parent.Activate
        .Activate
        .Range("L7").Select
        .Paste
    End With
End Sub



回答2:


Echoing Tim, this worked for me, resulting in non-grouped pictures. There should not be any reason you need to Activate the respective sheets.

The problem seems to be that you were using PasteSpecial method instead of Paste. I have a 2003 box at home I could verify on, but on 2010 Excel, the PasteSpecial method pasts the multiple pictures as a single object, whereas Paste puts them each individually.

Sub CopyAllPictures()
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim shSource As Worksheet
Dim shDest As Worksheet
Dim shp As Shape

Set wbSource = Workbooks("Book12")          'modify as needed
Set wbDest = Workbooks("Book13")            'modify as needed

Set shSource = wbSource.Sheets("Sheet1")    'modify as needed
Set shDest = wbDest.Sheets("Sheet1")        'modify as needed

shSource.Pictures.Copy
shDest.Range("L7").Paste


End Sub


来源:https://stackoverflow.com/questions/23686106/copying-multiple-images-from-one-workbook-to-another-as-separate-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!