Forum Discussion
Costafeller
Jul 18, 2021Copper Contributor
[VBA] Copy image to workbook
Hey everyone, I have an excel file with several formulas taking data from another "raw" excel file. This excel file is basically doing all the necessary calculations and automatically putting al...
- Jul 18, 2021
For example:
Sub CopyToNew() Dim w1 As Worksheet Dim wb As Workbook Dim w2 As Worksheet Set w1 = ActiveSheet w1.UsedRange.SpecialCells(xlCellTypeVisible).Copy Set wb = Workbooks.Add Set w2 = wb.Worksheets(1) w2.Range("A1").PasteSpecial xlPasteColumnWidths w2.Range("A1").PasteSpecial xlPasteValues w2.Range("A1").PasteSpecial xlPasteFormats w1.Shapes("Picture 4").Copy w2.Paste End Sub
Costafeller
Jul 19, 2021Copper Contributor
HansVogelaar
Jul 19, 2021MVP
Strange - when I tested the code, it ran without errors. The copied/pasted shapes kept the same names as the original.
- CostafellerJul 19, 2021Copper Contributor
HansVogelaar
So what are my options here?- HansVogelaarJul 19, 2021MVP
Could you attach a sample workbook that demonstrates the problem?
- CostafellerJul 21, 2021Copper Contributor
Well this is interesting... I had to strip the file so I could share it as you've requested, because of private information, and when I finished and tested the last code it works..
I'm assuming it's something not compatible with what I had before so I'll look deeper into it, but I have no idea what might be.
Edit: There was some issue with the name of the image, I just changed it and it works perfectly.
Thank you so much HansVogelaar! Your help was really really appreciated!