Pictures.insert excel 2010

sgremmo

Board Regular
Joined
Sep 1, 2004
Messages
55
With Excel 2010 the code below probably create a "link" because after renaming original picture and reopening excel file picture don't compare.

ActiveSheet.Pictures.Insert(filename).Select

How can I import image permanently into xlsx file?

Thank you.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
With Excel 2010 the code below probably create a "link" because after renaming original picture and reopening excel file picture don't compare.

ActiveSheet.Pictures.Insert(filename).Select

How can I import image permanently into xlsx file?

Hi sgremmo,

waiting for a better response, this is my dirty solution (but it works):
(P.S.: I apologize for my bad english)

Code:
Sub InsImmagine() 
     
  Dim sh As Worksheet 
  Dim rng As Range 
  Dim oPic As Object 
  Dim **** As String 
   
  Set sh = ActiveSheet 
  Set rng = Selection 
   
  **** = "D:\Immagini\pippo.gif" ' da cambiare 
   
  Set oPic = sh.Pictures.Insert(****) 
   
  sh.Shapes.AddPicture ****, msoFalse, msoTrue, _ 
    rng.Left, rng.Top, oPic.Width, oPic.Height 
   
  oPic.Delete 
   
  Set oPic = Nothing 
  Set rng = Nothing 
  Set sh = Nothing 
 
End Sub

Bye!
Scossa
 
Upvote 0
Another example

Code:
Sub piccy()
ActiveSheet.Pictures.Insert ("C:\example\pic.jpg")
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
    .LockAspectRatio = False
    .Top = Range("C3").Top
    .Left = Range("C3").Left
    .Height = Range("C3").RowHeight
    .Width = Range("C3").Width
End With
End Sub
 
Upvote 0
Another example

Code:
Sub piccy()
ActiveSheet.Pictures.Insert ("C:\example\pic.jpg")
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
    .LockAspectRatio = False
    .Top = Range("C3").Top
    .Left = Range("C3").Left
    .Height = Range("C3").RowHeight
    .Width = Range("C3").Width
End With
End Sub


Yes, simpler and better, but I modify it so, to maintain the aspect-ratio:

Code:
Sub piccy()
ActiveSheet.Pictures.Insert ("C:\example\pic.jpg")
With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
    .LockAspectRatio = True 'maintain aspect-ratio
    .Top = Range("C3").Top
    .Left = Range("C3").Left
    .Width = Range("C3").Width 'same width of C3
End With
End Sub
Bye!
Scossa
 
Upvote 0
Yes, simpler and better, but I modify it so, to maintain the aspect-ratio:

Hi Vog,
Yes, this is the normal way in Excel 2003 (and in 2007), but I can't try if your solution works in Excel 2010 (OP's Excel version) then waiting for sgremmo's response.

Bye!
Scossa
 
Upvote 0

Forum statistics

Threads
1,221,393
Messages
6,159,614
Members
451,578
Latest member
65goat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top