VBA erase Image control

(My English forgives me)

I need a help with this code, please help me I have 2 routines

Incluir, adds 7 controls image for line whenever he finds the word Graphic

Problem1, the image did not manage to put name to

Borrar, it must eliminate the images that it is in this sheet

Problem2, everything eliminates me and they are only the images those that I want to erase, since also I have buttons and cbo

If they want to prove to a sheet in Excel 2003, change the name to brand place 2 CommandButton, write in B10, B25, B45, 60, Graphics

and pegen this code

---------------------------------------------------------------

Dim nombrearchivo As String
Dim x, y, ancho, alto, i As Integer
Dim desde, hasta As Integer
Dim wbook As Workbook
Dim wsbrand As Worksheet
Dim celda As Range
Dim shapin As Shape

Private Sub CommandButton1_Click()
Call Incluir
End Sub

Private Sub CommandButton2_Click()
Call Borrar
End Sub

Sub Incluir()
Set wbook = Application.ActiveWorkbook
Set wsbrand = wbook.Sheets("Brand")
'Call OpenSheets
'wsbrand.Unprotect

ancho = 37.5
alto = ancho

hasta = wsbrand.Range("EndRowofBrand").Value
For i = 8 To hasta

If InStr(1, wsbrand.Range("B" & i), "Graphics") > 0 Then
Set celda = wsbrand.Range("B" & i)
y = celda.Top
'y = 371.25
x = 113
'wsbrand.Rows("B" & i).Height = ancho
For Image = 1 To 7
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Image.1", Link:=False, _
DisplayAsIcon:=False, Left:=x, Top:=y, Width:=ancho, Height:= _
alto).Select
x = x + ancho
' AddImage.Name = "Img" & Image & "_f" & i
Next Image

End If
Next i

End Sub

Sub Borrar()

Dim tmpImg As OLEObject
Dim Img As Class1
Dim wsSheet As Worksheet

Set wsSheet = ThisWorkbook.ActiveSheet

Set myControls = New Collection
For Each tmpImg In wsSheet.OLEObjects
If TypeOf tmpImg.Object Is MSForms.Image Then
Set Img = New Class1
Set Img.SheetImg = tmpImg.Object

End If
myControls.Add Img
Next

For Each shapin In wsSheet.Shapes
shapin.Delete
' If shapin.Type = msoPicture Then ''' Image
' shapin.Delete
' End If
Next
End Sub

'---------------------------- add that one modulates of class

Public WithEvents SheetImg As MSForms.Image





Answer this question

VBA erase Image control

  • vbuser1

    I've plugged this into your code and tested it, all ok.

    Adding and naming image controls
    - Sub Incluir()

    Dim objOLE As OLEObject

    For Image = 1 To 7
    Set objOLE = wsbrand.OLEObjects.Add(ClassType:="Forms.Image.1", _
    DisplayAsIcon:=False, Left:=x, Top:=y, Width:=ancho, Height:= _
    alto)
    objOLE.Name = "Img" & Image & "_f" & i
    x = x + ancho
    Next

    Deleting image controls - Sub Borrar()

    For Each tmpImg In ActiveSheet.OLEObjects
    If TypeOf tmpImg.Object Is MSForms.Image Then tmpImg.Delete

    Next







  • VBA erase Image control