Inserting a photo problem

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Inserting a photo problem

Post by ABabeNChrist »

When using this code below I received a compile error on "Me"

Code: Select all

Set Pic = Me.Pictures.Insert(PicLocation)
This code works good when tested in a new workbook using a command button. But when I put code in a module and using my UI editor to add it to my ribbon.
Here is the complete code

Code: Select all

  Sub RunPicture(control As IRibbonControl)
  Dim Pic As Excel.Picture
  Dim PicLocation As String
  Dim MyRange As Range
    
    PicLocation = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select  a picture")
    
    If PicLocation = "False" Then Exit Sub
    
    Set Pic = Me.Pictures.Insert(PicLocation)
    
      With Pic.ShapeRange

        .Left = ActiveCell.Left
        .Top = ActiveCell.Top
        .Width = 100
        .Height = 100
      
        .LockAspectRatio = msoFalse
    End With

End Sub
Compile error.JPG
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78437
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Inserting a photo problem

Post by HansV »

The keyword Me can only be used in class modules, including the modules belonging to a userform, workbook or worksheet.
In a userform module, Me refers to the userform, in the ThisWorkbook module it refers to the workbook, and in a worksheet module it refers to the worksheet.

In a standard module (listed under Modules in the Project Explorer), you can't use Me.

In this example, try changing Me to ActiveSheet.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Inserting a photo problem

Post by ABabeNChrist »

Thank you HansV
I learn something new everyday
It works great

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Inserting a photo problem

Post by ABabeNChrist »

Hi HansV
I was just wondering if this workbook that has this code, would still function correctly if used in a Windows Vista or Windows 7 operating system.

User avatar
HansV
Administrator
Posts: 78437
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Inserting a photo problem

Post by HansV »

I see no reason why it wouldn't.
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Inserting a photo problem

Post by ABabeNChrist »

Thank You HansV
I was just curious