Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2010 Macro Changes?

Status
Not open for further replies.

Enkrypted

Technical User
Sep 18, 2002
663
US
Was wondering if the macro coding has changed in the 2010 version of Excel. We have a workbook with several macros in it. A few of these macros are for adding pictures to the workbook. The code in the macros works for Excel 2003 and 2007, but doesn't do as it should in 2010.

The problem we are having with 2010 is that it isn't really adding the actual picture to the workbook, but rather a link to the image. When the file is saved and sent via e-mail to others, the image is not there, but instead the following error message show where the image should:

"The linked image cannot be displayed. The file may have been moved, renamed or deleted. Verify that the link points to the correct file and location."

We need it to be able to save the picture within the file itself. Here is the code for the macro:

Code:
Sub InsertBigPicture()

Dim myPicture As String, MyObj As Object

Range("h2").Select

myPicture = Application.GetOpenFilename _
    ("Pictures (*.gif; *.jpg; *.bmp; *.tif),*.gif; *.jpg; *.bmp; *.tif", _
        , "Select Picture to Import")

If myPicture = "False" Then Exit Sub

Set MyObj = ActiveSheet.Pictures.Insert(myPicture)

With MyObj
    With .ShapeRange
        .LockAspectRatio = msoTrue
        .Top = Range("H2").Top
        .Left = Range("H2").Left
        .Height = 160
        .Width = 215
        End With
    .Placement = xlMoveAndSize
End With

Set MyObj = Nothing

End Sub

Anyone have any ideas how to get this to save the picture and not just save a link to it?

Enkrypted
A+
 


You might want to try the AddPicture Method, where you can specify SaveWithDocument as True.

Code:
expression.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)

Check VBA Help

It might look like...
Code:
Set MyObj = ActiveSheet.Shapes.AddPicture( _
   myPicture, _
   False, _
   True, _
   Range("H2").Left, _
   Range("H2").Top, _
   215, _
   160)

With MyObj
    .ShapeRange.LockAspectRatio = msoTrue
    .Placement = xlMoveAndSize
End With


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top