Inserção de imagem ...
 
Notifications
Clear all

Inserção de imagem em userform dá erro!

3 Posts
2 Usuários
0 Reactions
417 Visualizações
(@nuelss)
Posts: 0
New Member
Topic starter
 

Boa tarde a todos.

Estou criando uma planilha para facilitar o acesso a alguns códigos (uma imagem vale mais do que mil palavras ...).
O problema é que quando eu utilizo código manual (item a item) as imagens aparecem, mas quando eu evoluo a rotina de inserção para um looping (for ... next) dá um erro 424, dizendo que o objeto é obrigatório.
Ficarei muito agradecido se alguém puder me ajudar a resolver o problema.

Segue os códigos abaixo:

Código que funciona:

Private Sub UserForm_Initialize()

Dim nrepeat
Dim contimg
Dim nimage
Dim nlabel
Dim namelin
Dim imglin

nrepeat = 0
contimg = 1
largelinel = Sheets("dados").Range("AI2")
dire = Sheets("pedido").Range("P1")

' este código de carregamento das imagens é alimentado manualmente, não é viável

Set Image1.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label201.Caption = "Xten"
Set Image2.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label202.Caption = "Link Xplus"
Set Image3.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label203.Caption = "Link Plus"
Set Image4.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label204.Caption = "Link"
Set Image5.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label205.Caption = "Geral"
Set Image6.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label206.Caption = "Trendy"
Set Image7.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label207.Caption = "Top Millennium"
Set Image8.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label208.Caption = "Venus"
Set Image9.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label209.Caption = "Zero7"
Set Image10.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label210.Caption = "Zero9"
Set Image11.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label211.Caption = "SmartBlack"
Set Image12.Picture = LoadPicture(dire & "MESAHIPUP.wmf")
Label212.Caption = "Open"

End Sub

Còdigo que NÂO está funcionando:

Private Sub UserForm_Initialize()

Dim nrepeat
Dim contimg
Dim nimage
Dim nlabel
Dim namelin
Dim imglin

nrepeat = 0
contimg = 1
largelinel = Sheets("dados").Range("AI2")
dire = Sheets("pedido").Range("P1")

For nrepeat = 0 To largelinel - 1

    nimage = CStr("Image" & contimg)
    imglin = Sheets("dados").Range(CStr("AG" & contimg + 1))
    nlabel = CStr("Label" & 200 + contimg)
    namelin = Sheets("dados").Range(CStr("AF" & contimg + 1))
    
    Set nimage.Picture = LoadPicture(dire & imglin & ".wmf")
    nlabel.Caption = namelin
    contimg = contimg + 1

Next nrepeat

End Sub


 
Postado : 30/09/2015 11:09 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Anexe um modelo de acordo com as regras do forum, ficara mais facil analisar.

 
Postado : 30/09/2015 7:42 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Como disse o colega Mauro, com um modelo ficará muito mais simples, mas verifique a passagem dos paramentros. Em um formulario, o objeto imagem passa a ser um controle do formulario e como tal deve ser referenciado

 
Postado : 01/10/2015 12:03 pm