Help with this Code

fULMIEX

New Member
Joined
May 9, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello All I created this code. evrithing seems fine but ALL THE TIME error 5
VBA Code:
Sub Exportar_Imagenes()
    Dim img As Shape, tempChart As ChartObject
    Dim sPath As String, sName As String
    Dim imgEncontrada As Boolean
    
    ' Ruta donde se guardarán las imágenes
    sPath = "C:\Users\Mercadeo03\Carbone Dropbox\mercadeo carbone\Fotos Productos - Shopify - VTEX - Roberto\Repuestos TOTAL\Repuestos 08-05-24\Fotos\"
    
    ' Bandera para verificar si se encontraron imágenes
    imgEncontrada = False
    
    ' Recorre todas las formas en la hoja activa
    For Each img In ActiveSheet.Shapes
        ' Verifica si la forma tiene una celda asociada y si esa celda está en la columna B
        If Not img.TopLeftCell Is Nothing And img.TopLeftCell.Column = 2 Then
            ' Se encontró una imagen en la columna B
            imgEncontrada = True
            
            ' Obtiene el nombre de archivo de la celda en la columna A
            sName = img.TopLeftCell.Offset(0, -1).Value
            
            ' Verifica si el nombre de archivo no está vacío
            If sName <> "" Then
                ' Copia la imagen al portapapeles
                img.CopyPicture
                
                ' Crea un objeto de gráfico temporal
                Set tempChart = ActiveSheet.ChartObjects.Add(0, 0, img.Width, img.Height)
                
                ' Pega la imagen en el gráfico
                With tempChart
                    .Activate
                    .Border.LineStyle = xlLineStyleNone
                    .Chart.Paste
                    ' Exporta la imagen como archivo GIF
                    .Chart.Export sPath & sName & ".gif", "GIF"
                    .Delete
                End With
            End If
        End If
    Next
    
    ' Si no se encontró ninguna imagen en la columna B, muestra un mensaje
    If Not imgEncontrada Then
        MsgBox "No se encontraron imágenes en la columna B.", vbInformation
    End If
End Sub

Any help would be gratly apreciated. Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Not enough information. For any error (compile error or runtime error) you should report 3 things:

1. Error number
2. Error message
3. Line of code that generates the error.
 
Upvote 0

Forum statistics

Threads
1,216,129
Messages
6,129,047
Members
449,482
Latest member
al mugheen

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