Reputation: 45
I am having a problem to insert a picture (and save within the document) in a worksheet. I am not an expert in VBA, so I really need someone to help me find the error.
Here is the code:
copy/paste image0 Sheets("Ficha_AMV").Select Range("c3").Select Selection.Copy ws.Select Range("c3").Select 'ActiveSheet.Paste ActiveSheet.PasteSpecial Format:="Picture (JPEG)", Link:=False, _ DisplayAsIcon:=False
So in C3 in sheet "Ficha_AMV" I have a picture, and my goal is to copy it to a new worksheet ("ws"). I need this picture saved within the ws worksheet, (not with a link).
So I tried
activesheet.paste
and it copied with the link
then I tried with
ActiveSheet.PasteSpecial Format:="Picture (JPEG)", Link:=False, _DisplayAsIcon:=False
and it returned the following error
Run-time error '1004':PasteSpecialo method of Worksheet class failed
Upvotes: 1
Views: 10163
Reputation: 84465
If it already exists as a picture then use the name of the object
Option Explicit
Sub test()
Dim wb As Workbook
Dim wsSource As Worksheet
Dim ws As Worksheet
Set wb = ThisWorkbook
Set wsSource = wb.Worksheets("Ficha_AMV")
Set ws = wb.Worksheets("Sheet1") 'change as appropriate
Dim pic As Shape
Set pic = wsSource.Shapes("Picture 2") 'change as appropriate
pic.Copy
ws.Range("C3").PasteSpecial
End Sub
If it is not already a picture use:
Option Explicit
Sub test()
Dim wb As Workbook
Dim wsSource As Worksheet
Dim ws As Worksheet
Set wb = ThisWorkbook
Set wsSource = wb.Worksheets("Ficha_AMV")
Set ws = wb.Worksheets("Sheet1") 'change as appropriate
wsSource.Range("C3").CopyPicture
ws.Range("C3").PasteSpecial
End Sub
Upvotes: 2