INSERIR IMAGEM EM USERFORM

PABLOMOREIRAGV 21/09/2010 12:36:54
#353497
E aí gente!!!

Alguém sabe me dizer como faço para colocar um botão em um userform do excel que teria a função de abrir a janela [Ô]INSERIR IMAGEM[Ô] e a imagem escolhida e inserida aparecesse em um controle Image que fica também no mesmo userform. Só que eu quero que essa imagem fique fixa no arquivo para que no caso de mandar este mesmo arquivo por email não necessite de mandar as imagens em uma pasta separada.
PABLOMOREIRAGV 22/09/2010 08:32:52
#353567
E aí gente,

O código abaixo tem a função de abrir a janela de inserção de imagem que aparece direto em um controle Image. Só que tem um problema, quando o controle Image é colocado diretamente em uma planilha do excel funciona blz, consegue-se salvar e levar o arquivo pra qualquer lugar que a imagem fica fixa. Mas quando este mesmo código é colocado em um botão que fica dentro de um controle Multipage em um Userform, consegue-se apenas colocar a imagem, mas no momento em que se fecha a planilha, o controle Image fica em branco quando aberto novamente. O que devo fazer? Peço os amigos que por favor me ajudem nesta questão. Obrigado.

Selecionar imagem:

Private Sub CommandButton3_Click()
Dim myPictName As Variant


myPictName = Application.GetOpenFilename _
(filefilter:=[Ô]Picture Files,*.jpg;*.bmp;*.tif;*.gif[Ô])
With myPictName

If myPictName = False Then
Exit Sub
End If


Me.Image1.Picture = LoadPicture(myPictName)

End With
End Sub


Excluir Imagem:

With Image1
.Picture = Nothing
End With
PABLOMOREIRAGV 22/09/2010 12:21:35
#353588
Alguém tem alguma idéia?
JAMESBOND007 23/09/2010 11:14:22
#353661
Veja se isto pode te ajudar

Option Explicit

Const colCodigoDoFornecedor As Integer = 1
Const colNomeDaEmpresa As Integer = 2
Const colNomeDoContato As Integer = 3
Const colCargoDoContato As Integer = 4
Const colEndereco As Integer = 5
Const colCidade As Integer = 6
Const colRegiao As Integer = 7
Const colCEP As Integer = 8
Const colPais As Integer = 9
Const colTelefone As Integer = 13
Const colFax As Integer = 11
Const colHomePage As Integer = 12
Const colimage As Integer = 10
Const indiceMinimo As Byte = 3
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643

Private wsCadastro As Worksheet
Private indiceRegistro As Long

Private Sub btnCancelar_Click()
btnOK.Enabled = False
btnCancelar.Enabled = False
Call DesabilitaControles
Call CarregaDadosInicial
Call HabilitaBotoesAlteracao
End Sub

Private Sub btnOK_Click()
Dim proximoId As Long

[ô]Altera
If optAlterar.Value Then
Call SalvaRegistro(CLng(txtCodigoFornecedor.Text), indiceRegistro)
lblMensagem.Caption = [Ô]Registro salvo com sucesso[Ô]
End If
[ô]Novo
If optNovo.Value Then
proximoId = PegaProximoId
[ô]pega a próxima linha
Dim proximoIndice As Long
proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
Call SalvaRegistro(proximoId, proximoIndice)
txtCodigoFornecedor = proximoId
lblMensagem.Caption = [Ô]Registro salvo com sucesso[Ô]
End If
[ô]Excluir
If optExcluir.Value Then
Dim result As VbMsgBoxResult
result = MsgBox([Ô]Deseja excluir o registro nº [Ô] & txtCodigoFornecedor.Text & [Ô] ?[Ô], vbYesNo, [Ô]Confirmação[Ô])

If result = vbYes Then
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCodigoDoFornecedor), wsCadastro.Cells(indiceRegistro, colCodigoDoFornecedor)).EntireRow.Delete
Call CarregaDadosInicial
lblMensagem.Caption = [Ô]Registro excluído com sucesso[Ô]
End If
End If

Call HabilitaBotoesAlteracao
Call DesabilitaControles

End Sub


Private Sub btnPesquisar_Click()
frmPesquisa.Show
End Sub

Private Sub frmRegistro_Click()

End Sub

Private Sub Image1_Click()
Dim fname As String
[ô] Display the Open dialog box.
fname = Application.GetOpenFilename(filefilter:= _
[Ô]Image Files(*.jpg),*.jpg[Ô], Title:=[Ô]Select Image To Open[Ô])

[ô] Load the picture into the Image control.
Image1.Picture = LoadPicture(fname)


[ô] Update the UserForm.
Me.Repaint



End Sub




Private Sub optAlterar_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> [Ô][Ô] Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
[ô]dá o foco ao primeiro controle de dados
txtNomeEmpresa.SetFocus
Else
lblMensagem.Caption = [Ô]Não há registro a ser alterado[Ô]
End If
End Sub

Private Sub optExcluir_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> [Ô][Ô] Then
Call DesabilitaBotoesAlteracao
lblMensagem.Caption = [Ô]Modo de exclusão. Confira o dados do registro antes de excluí-lo[Ô]
Else
lblMensagem.Caption = [Ô]Não há registro a ser excluído[Ô]
End If
End Sub

Private Sub optNovo_Click()
Call LimpaControles
Call HabilitaControles
Call DesabilitaBotoesAlteracao
[ô]dá o foco ao primeiro controle de dados
txtNomeEmpresa.SetFocus
End Sub



Private Sub UserForm_Initialize()
Set wsCadastro = ThisWorkbook.Worksheets([Ô]Fornecedores[Ô])
Call HabilitaBotoesAlteracao
Call CarregaDadosInicial
Call DesabilitaControles
End Sub

Private Sub btnAnterior_Click()
If indiceRegistro > indiceMinimo Then
indiceRegistro = indiceRegistro - 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnPrimeiro_Click()
indiceRegistro = indiceMinimo
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnProximo_Click()
If indiceRegistro < wsCadastro.UsedRange.Rows.Count Then
indiceRegistro = indiceRegistro + 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnUltimo_Click()
indiceRegistro = wsCadastro.UsedRange.Rows.Count
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub CarregaDadosInicial()
indiceRegistro = 2
Call CarregaRegistro
End Sub

Private Sub CarregaRegistro()
[ô]carrega os dados do primeiro registro

With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colCargoDoContato)) Then
Me.txtCodigoFornecedor.Text = .Cells(indiceRegistro, colCodigoDoFornecedor).Value
Me.txtNomeEmpresa.Text = .Cells(indiceRegistro, colNomeDaEmpresa).Value
Me.txtNomeContato.Text = .Cells(indiceRegistro, colNomeDoContato).Value
Me.txtCargoContato.Text = .Cells(indiceRegistro, colCargoDoContato).Value
Me.txtEndereco.Text = .Cells(indiceRegistro, colEndereco).Value
Me.TxtCidade.Text = .Cells(indiceRegistro, colCidade).Value
Me.txtRegiao.Text = .Cells(indiceRegistro, colRegiao).Value
Me.txtCEP.Text = .Cells(indiceRegistro, colCEP).Value
Me.txtPais.Text = .Cells(indiceRegistro, colPais).Value
Me.txtTelefone.Text = .Cells(indiceRegistro, colTelefone).Value
Me.txtFax.Text = .Cells(indiceRegistro, colFax).Value
Me.txtHomePage.Text = .Cells(indiceRegistro, colHomePage).Value
????????????????????????????????????????? Como se carrega a imagem aqui?
End If
End With

Call AtualizaRegistroCorrente
End Sub

Public Sub CarregaRegistroPorIndice(ByVal indice As Long)
[ô]carrega os dados do registro baseado no índice
indiceRegistro = indice

Call CarregaRegistro
End Sub

Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
With wsCadastro
.Cells(indice, colCodigoDoFornecedor).Value = id
.Cells(indice, colNomeDaEmpresa).Value = Me.txtNomeEmpresa.Text
.Cells(indice, colNomeDoContato).Value = Me.txtNomeContato.Text
.Cells(indice, colCargoDoContato).Value = Me.txtCargoContato.Text
.Cells(indice, colEndereco).Value = Me.txtEndereco.Text
.Cells(indice, colCidade).Value = Me.TxtCidade.Text
.Cells(indice, colRegiao).Value = Me.txtRegiao.Text
.Cells(indice, colCEP).Value = Me.txtCEP.Text
.Cells(indice, colPais).Value = Me.txtPais.Text
.Cells(indice, colTelefone).Value = Me.txtTelefone.Text
.Cells(indice, colFax).Value = Me.txtFax.Text
.Cells(indice, colHomePage).Value = Me.txtHomePage.Text
.Cells(indice, colimage).Value = Me.Image1.Picture
End With

Call AtualizaRegistroCorrente
End Sub
Private Function PegaProximoId() As Long
Dim rangeIds As Range
[ô]pega o range que se refere a toda a coluna do código (id)
Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colCodigoDoFornecedor), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCodigoDoFornecedor))
PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function


Citação:

isto e so um exemplo tente implementar. OBS:.Para que funcione corretamente precisa entender todo o processo do código.

PABLOMOREIRAGV 28/09/2010 17:49:49
#354033
Oi gente,

Segue link da planilha modelo para entenderem melhor o que estou querendo dizer. Notem que a imagem permanece quando o controle image é inserido direto na planilha, mas quando está em um userform a figura naum fica fixa no formulario. Alguém pode me ajudar. Desde já agradeço.

Exemplo:

http://www.4shared.com/file/Bg-9GlyY/TESTE_-_IMAGE.html
PABLOMOREIRAGV 29/09/2010 11:06:40
#354102
Alguém tem alguma idéia?
PABLOMOREIRAGV 06/10/2010 08:31:43
#354510
Infelizmente não consegui solicinar o meu problema. Mas se alguém tiver idéia e puder ajudar o meu email é pablo.scobar@hotmail.com , eu reabro o tópico e pontuo a pessoa.
Tópico encerrado , respostas não são mais permitidas