¿Cómo puedo mostrar una URL como imagen en una celda de Excel?

¿Cómo puedo mostrar una URL como imagen en una celda de Excel?

¿Alguien puede explicarme cómo convertir un enlace web (URL) en una imagen?

Imagen de ejemplo (la URL es http://cache.lego.com/media/bricks/5/1/4667591.jpg)

http://cache.lego.com/media/bricks/5/1/4667591.jpg

Lo que estoy tratando de hacer es hacer que una lista de piezas que he descargado muestre la imagen en lugar del enlace web anterior.

Lo que tengo en J2 a J1903 es:

http://cache.lego.com/media/bricks/5/1/4667591.jpg
http://cache.lego.com/media/bricks/5/1/4667521.jpg
...

Lo que me gustaría hacer es obtener Excel para convertir todos estos (10903 de ellos) en imágenes (tamaño de celda 81x81).

¿Alguien puede explicarme paso a paso cómo puedo hacer esto?

Respuesta1

Si tiene un conjunto de enlaces en la columnajcomo:

ingrese la descripción de la imagen aquí

y ejecutas esta breve macro de VBA:

Sub InstallPictures()
    Dim i As Long, v As String
    For i = 2 To 1903
        v = Cells(i, "J").Value
        If v = "" Then Exit Sub
        With ActiveSheet.Pictures
            .Insert (v)
        End With
    Next i
End Sub

Se abrirá cada uno de los enlaces y la imagen asociada se colocará en la hoja de trabajo.

Las imágenes deben tener el tamaño y la ubicación adecuados.

EDITAR #1:

Las macros son muy fáciles de instalar y usar:

  1. ALT-F11 abre la ventana VBE
  2. ALT-I ALT-M abre un módulo nuevo
  3. pegue las cosas y cierre la ventana de VBE

Si guarda el libro, la macro se guardará con él. Si está utilizando una versión de Excel posterior a 2003, debe guardar el archivo como .xlsm en lugar de .xlsx.

ingrese la descripción de la imagen aquí

Para eliminar la macro:

  1. abrir la ventana VBE como arriba
  2. borrar el código
  3. cerrar la ventana VBE

Para usar la macro de Excel:

  1. ALT-F8
  2. Seleccione la macro
  3. Toque EJECUTAR

Para obtener más información sobre las macros en general, consulte:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

y

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

¡Las macros deben estar habilitadas para que esto funcione!

EDITAR #2:

Para evitar detenerse ante errores de recuperación, utilice esta versión:

Sub InstallPictures()
    Dim i As Long, v As String
    On Error Resume Next
        For i = 2 To 1903
            v = Cells(i, "J").Value
            If v = "" Then Exit Sub
            With ActiveSheet.Pictures
                .Insert (v)
            End With
        Next i
    On Error GoTo 0
End Sub

Respuesta2

Esta es mi modificación:

  • Reemplazar celda con enlace con imagen (no una columna nueva)
  • Haga que las imágenes se guarden con un documento (en lugar de enlaces que pueden ser frágiles)
  • Haga las imágenes un poco más pequeñas para que tengan la posibilidad de clasificarse con sus celdas.

Código a continuación:

Option Explicit
Dim rng As Range
Dim cell As Range
Dim Filename As String

Sub URLPictureInsert()
    Dim theShape As Shape
    Dim xRg As Range
    Dim xCol As Long
    On Error Resume Next
    Application.ScreenUpdating = False
    ' Set to the range of cells you want to change to pictures
    Set rng = ActiveSheet.Range("A2:A600")  
    For Each cell In rng
        Filename = cell
        ' Use Shapes instead so that we can force it to save with the document
        Set theShape = ActiveSheet.Shapes.AddPicture( _
            Filename:=Filename, linktofile:=msoFalse, _
            savewithdocument:=msoCTrue, _
            Left:=cell.Left, Top:=cell.Top, Width:=60, Height:=60)
        If theShape Is Nothing Then GoTo isnill
        With theShape
            .LockAspectRatio = msoTrue
            ' Shape position and sizes stuck to cell shape
            .Top = cell.Top + 1
            .Left = cell.Left + 1
            .Height = cell.Height - 2
            .Width = cell.Width - 2
            ' Move with the cell (and size, though that is likely buggy)
            .Placement = xlMoveAndSize
        End With
        ' Get rid of the 
        cell.ClearContents
isnill:
        Set theShape = Nothing
        Range("A2").Select

    Next
    Application.ScreenUpdating = True

    Debug.Print "Done " & Now

End Sub

Respuesta3

Éste funciona mucho mejor porque la imagen termina al lado de la celda a la que pertenece.

Option Explicit
Dim rng As Range
Dim cell As Range
Dim Filename As String

Sub URLPictureInsert()
    Dim theShape As Shape
    Dim xRg As Range
    Dim xCol As Long
    On Error Resume Next
    Application.ScreenUpdating = False
    Set rng = ActiveSheet.Range("C1:C3000")   ' <---- ADJUST THIS
    For Each cell In rng
        Filename = cell
        If InStr(UCase(Filename), "JPG") > 0 Then   '<--- ONLY USES JPG'S
            ActiveSheet.Pictures.Insert(Filename).Select
            Set theShape = Selection.ShapeRange.Item(1)
            If theShape Is Nothing Then GoTo isnill
            xCol = cell.Column + 1
            Set xRg = Cells(cell.Row, xCol)
            With theShape
                .LockAspectRatio = msoFalse
                .Width = 100
                .Height = 100
                .Top = xRg.Top + (xRg.Height - .Height) / 2
                .Left = xRg.Left + (xRg.Width - .Width) / 2
            End With
isnill:
            Set theShape = Nothing
            Range("A2").Select
        End If
    Next
    Application.ScreenUpdating = True

    Debug.Print "Done " & Now

End Sub

información relacionada