Está declarado com As long . O codigo inteiro é esse abaixo
Código: Selecionar todos
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 = 10
Const colFax As Integer = 11
Const colHomePage As Integer = 12
Const indiceMinimo As Byte = 2
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643
Const nomePlanilhaCadastro As String = "Fornecedores"
Const nomePlanilhaCadastro3 As String = "Histórico"
Dim sNomeConfirma As String
Dim Cancel As String
Dim trava As String
Private wsCadastro As Worksheet
Private wsCadastro1 As Worksheet
Private wsCadastro2 As Worksheet
Private wbCadastro As Workbook
Private wbCadastro1 As Workbook
Private wbCadastro3 As Workbook
Dim indiceRegistro As Integer
Private indiceRegistro2 As Long
Private Codigo As Long
Private Sub btnCancelar_Click()
btnOK.Enabled = False
btnCancelar.Enabled = False
Call DesabilitaControles
Call CarregaDadosInicial
Call HabilitaBotoesAlteracao
Call esconder
End Sub
Private Sub btnOK_Click()
Dim proximoId As Long
Call PegaProximoId2
Call AtualizarArquivo(False)
'proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
TextBox5.Value = PegaProximoId2
'Call SalvaRegistro(proximoId, proximoIndice)
Call SalvaRegistro(CLng(txtCodigoFornecedor.Text), indiceRegistro)
txtCodigoFornecedor = proximoId
lblMensagem.Caption = "Registro salvo com sucesso"
End Sub
Private Sub btnPesquisar_Click()
frmPesquisa.Show
End Sub
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox4.Text = "Devoluçao"
TextBox8.Enabled = False
Else
TextBox4.Text = "Entrada"
TextBox8.Enabled = True
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True And Label47.Caption = "L4" Then
TextBox6.Enabled = True
TextBox7.Enabled = True
TextBox9.Enabled = True
TextBox4.Text = "Ordem de compra"
TextBox6.SetFocus
Else
CheckBox2.Value = False
MsgBox "Vc não está autorizado a criar pedido de compra"
End If
If CheckBox2.Value = False Then
TextBox6.Enabled = False
TextBox7.Enabled = False
TextBox9.Enabled = False
TextBox3.Text = " "
End If
End Sub
Private Sub CommandButton15_Click()
Unload frmCadastro
UserForm5.Show
ActiveWindow.DisplayWorkbookTabs = True
UserForm5.TextBox1.Text = " "
UserForm5.TextBox2.Value = " "
End Sub
Private Sub CommandButton16_Click()
End Sub
Private Sub CommandButton3_Click()
Dim arqAAbrir
If txtNomeEmpresa = "" Then
MsgBox "Digite ou pesquise Cliente.", 64, "Cadastro"
Exit Sub
End If
arqAAbrir = Application.GetOpenFilename("Arquivos de imagens (*.jpg;*.bmp;*.wmf), *.txt,*.bmp,*.wmf")
If arqAAbrir <> False Then
txtHomePage.Text = LCase(arqAAbrir)
Image_Cliente.Picture = LoadPicture(txtHomePage.Text)
Image_Cliente.PictureSizeMode = fmPictureSizeModeStretch 'fmPictureSizeModeZoom
End If
End Sub
Private Sub CommandButton17_Click()
Call locTeste2
End Sub
Private Sub CommandButton19_Click()
Dim i As Long
Dim valor As Double
For i = 1 To Me.ListView1.ListItems.Count
valor = valor + CDbl(Me.ListView1.ListItems(i).ListSubItems(5))
Next i
Label66.Caption = valor
Label66.Caption = Format(Label66.Caption, "#,###0.#0")
End Sub
Private Sub CommandButton20_Click()
Call Sair
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub frmRegistro_Click()
End Sub
Private Sub Image_Cliente_Click()
End Sub
Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)
End Sub
Private Sub MultiPage1_Change()
End Sub
Private Sub OptionButton1_Click()
End Sub
Private Sub TextBox2_Change()
Call Calculardesconto
Call Minmax
End Sub
Private Sub TextBox3_Change()
TextBox3.Value = UCase(TextBox3.Value)
End Sub
Pt
End Sub
Private Sub TextBox4_Change()
End Sub
Private Sub TextBox7_Change()
'Call locTeste
End Sub
Private Sub TextBox8_Change()
End Sub
Private Sub txtCargoContato_Change()
If txtCargoContato.Value = "" Then
ElseIf IsNumeric(txtCargoContato.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
txtCargoContato.Value = ""
txtCargoContato.SetFocus
End If
End Sub
Private Sub txtCEP_Change()
If txtCEP.Value = "" Then
ElseIf IsNumeric(txtCEP.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
txtCEP.Value = ""
txtCEP.SetFocus
End If
End Sub
Private Sub txtCidade_Change()
If txtCidade.Value = "" Then
ElseIf IsNumeric(txtCidade.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
txtCidade.Value = ""
txtCidade.SetFocus
End If
End Sub
Private Sub txtEndereco_Change()
If txtEndereco.Value = "" Then
ElseIf IsNumeric(txtEndereco.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
txtEndereco.Value = ""
txtEndereco.SetFocus
Else
Call Calcular_Valores4
End If
End Sub
Private Sub txtHomePage_Change()
On Error GoTo ErrorHandler
Image_Cliente.Picture = LoadPicture(txtHomePage)
Image_Cliente.PictureSizeMode = fmPictureSizeModeStretch
ErrorHandler:
If Err.Number = 71 Then MsgBox ("Acerte Diretórios e Arquivos de Fotos")
Err.Clear
Resume Next
End Sub
Private Sub txtNomeContato_Change()
txtNomeContato.Value = UCase(txtNomeContato.Value)
End Sub
Private Sub txtNomeEmpresa_Exit(ByVal Cancel As MSForms.ReturnBoolean)
' LocAgenda 'Ao sair do textbox irá procurar se o cadastro já existe
Dim listagenda As Long
If txtNomeEmpresa.Value = listagenda Then ' Se existir ....
txtNomeEmpresa.SelStart = 0 ' Seleciona todo.........
txtNomeEmpresa.SelLength = Len(txtNomeEmpresa.Text) 'O texto do TxtBox para dgitar outro
Cancel = True 'Trava todos os outros campos impedindo qq ação
Else
Cancel = False 'Se o cadastro não existir, libera os Conttroles e continua com sua rotina
End If
End Sub
Private Sub txtPais_Change()
If txtPais.Value = "" Then
ElseIf IsNumeric(txtPais.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
txtPais.Value = ""
txtPais.SetFocus
End If
End Sub
Private Sub txtRegiao_Change()
txtRegiao.Value = UCase(txtRegiao.Value)
End Sub
Private Sub txtTelefone_Change()
End Sub
Private Sub UserForm_Initialize()
With Application
.WindowState = xlMaximized
End With
With Me
.Top = Application.Top
.Left = Application.Left
.Height = Application.Height
.Width = Application.Width
End With
Call DefinePlanilhaDados
'Call CarregaDadosInicial
Label51.Caption = Sheets("Acessos").Range("E3")
Label56.Caption = Sheets("Acessos").Range("F3")
Label53.Caption = Now()
Label58.Caption = IsoWeekNumber(Now)
trava = True
Call PreencherListView
Call Calcular_Valores4
TextBox7.SetFocus
End Sub
Private Sub CarregaDadosInicial()
'indiceRegistro = 2
'Call CarregaRegistro
End Sub
Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
Dim indiceRegistro As Long
With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colCodigoDoFornecedor)) 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.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
Me.TextBox1.Text = .Cells(indiceRegistro, colFax).Value
Me.TextBox6.Text = .Cells(indiceRegistro, colEndereco).Value
End If
End With
Call Calculardesconto
Call Minmax
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 AtualizarArquivo(ByVal ReadOnly As Boolean)
Dim caminhoCompleto As String
'fecha o arquivo de dados e tenta abrí-lo
'guarda o caminho
caminhoCompleto = wbCadastro.FullName
wbCadastro.Saved = True
wbCadastro.Close SaveChanges:=False
'abre o arquivo em modo escrita
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=ReadOnly)
'oculta a janela colocar como false
wbCadastro.Windows(1).Visible = True
'reatribui a planilha de cadastro
Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)
Set wsCadastro1 = wbCadastro.Worksheets(nomePlanilhaCadastro3)
End Sub
Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
'tenta abrir o arquivo em modo escrita
Call AtualizarArquivo(False)
Call Minmax
With wsCadastro
Codigo = id
.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, 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
End With
Call Zarq
Call wbCadastro.Save
'abre o arquivo novamente em modo leitura
Call AtualizarArquivo(True)
Call AtualizaRegistroCorrente
Call CarregaRegistro
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
Private Function PegaProximoId2() As Long
Dim rangeIds As Range
'pega o range que se refere a toda a coluna do código (id)
Set rangeIds = wsCadastro1.Range(wsCadastro1.Cells(indiceMinimo, colCodigoDoFornecedor), wsCadastro1.Cells(wsCadastro1.UsedRange.Rows.Count, colCodigoDoFornecedor))
PegaProximoId2 = WorksheetFunction.Max(rangeIds) + 1
End Function
Public Function ProcuraIndiceRegistroPodId(ByVal id As Long) As Long
Dim i As Long
Dim retorno As Long
Dim encontrado As Boolean
i = indiceMinimo
With wsCadastro
Do While Not IsEmpty(.Cells(i, colCodigoDoFornecedor))
If .Cells(i, colCodigoDoFornecedor).Value = id Then
retorno = i
encontrado = True
Exit Do
End If
i = i + 1
Loop
End With
'caso não encontre o registro, retorna -1
If Not encontrado Then
retorno = -1
End If
ProcuraIndiceRegistroPodId = i
End Function
Private Sub DefinePlanilhaDados()
Dim abrirArquivo As Boolean
Dim wb As Workbook
Dim caminhoCompleto As String
Dim ARQUIVO_DADOS As String
Dim PASTA_DADOS As String
abrirArquivo = True
ARQUIVO_DADOS = Range("ARQUIVO_DADOS").Value
PASTA_DADOS = Range("PASTA_DADOS").Value
If ThisWorkbook.Name <> ARQUIVO_DADOS Then
'monta a string do caminho completo
If PASTA_DADOS = vbNullString Or PASTA_DADOS = "" Then
caminhoCompleto = Replace(ThisWorkbook.FullName, ThisWorkbook.Name, vbNullString) & ARQUIVO_DADOS
Else
If Right(PASTA_DADOS, 1) = "\" Then
caminhoCompleto = PASTA_DADOS & ARQUIVO_DADOS
Else
caminhoCompleto = PASTA_DADOS & "\" & ARQUIVO_DADOS
End If
End If
'verifica se o arquivo não está aberto
For Each wb In Application.Workbooks
If wb.Name = ARQUIVO_DADOS Then
abrirArquivo = False
Exit For
End If
Next
'atribui o arquivo
If abrirArquivo Then
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=True)
Else
Set wbCadastro = Workbooks(ARQUIVO_DADOS)
End If
Else
Set wbCadastro = ThisWorkbook
Set wbCadastro1 = ThisWorkbook
End If
Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)
Set wsCadastro1 = wbCadastro.Worksheets(nomePlanilhaCadastro3)
'oculta o arquivo de dados alterar para false
wbCadastro.Windows(1).Visible = True
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'fecha a planilha de dados, se estiver aberta
If Not wbCadastro Is Nothing Then
wbCadastro.Saved = True
End If
Set wbCadastro = Nothing
End Sub
Sub Zarq()
Dim arq As Integer
With wsCadastro1
arq = wsCadastro1.Range("A65536").End(xlUp).Offset(1, 0).Row
wsCadastro1.Range("A" & arq).Value = TextBox5.Value
wsCadastro1.Range("B" & arq).Value = Label51.Caption
wsCadastro1.Range("C" & arq).Value = Now()
wsCadastro1.Range("D" & arq).Value = txtNomeEmpresa.Value
If trava = False Then
wsCadastro1.Range("E" & arq).Value = txtCodigoFornecedor
Else
wsCadastro1.Range("E" & arq).Value = Codigo
End If
wsCadastro1.Range("F" & arq).Value = txtNomeContato.Text
wsCadastro1.Range("G" & arq).Value = txtRegiao.Text
wsCadastro1.Range("H" & arq).Value = txtCargoContato.Text
wsCadastro1.Range("I" & arq).Value = txtCidade.Text
wsCadastro1.Range("j" & arq).Value = TextBox6.Text
wsCadastro1.Range("K" & arq).Value = txtCEP.Text
wsCadastro1.Range("L" & arq).Value = txtPais.Text
wsCadastro1.Range("M" & arq).Value = txtTelefone.Text
wsCadastro1.Range("N" & arq).Value = TextBox1.Text
wsCadastro1.Range("O" & arq).Value = TextBox2.Text
wsCadastro1.Range("P" & arq).Value = txtFax.Text
wsCadastro1.Range("Q" & arq).Value = TextBox4.Text
'wsCadastro1.Range("R" & arq).Value = TextBox3.Text antigo N/F
wsCadastro1.Range("S" & arq).Value = Label58.Caption
End With
End Sub
Sub Regra_acesso()
If Label56 = "L3" Then
optNovo.Enabled = False
optExcluir.Enabled = False
txtCEP.Visible = False
txtPais.Visible = False
txtTelefone.Visible = False
txtCargoContato.Visible = False
optAlterar.Enabled = False
'Falta não gera relatório
Else
optNovo.Visible = True
End If
If Label56 = "L2" Then
optNovo.Enabled = False
optExcluir.Enabled = False
txtCEP.Visible = False
txtPais.Visible = False
txtTelefone.Visible = False
End If
End Sub
Sub Calculardesconto()
Dim ant As Currency
Dim nov As Currency
If TextBox2.Value = "" Then
'txtFax.Value = 0
ElseIf IsNumeric(TextBox2.Text) = False Then
MsgBox "Digite apenas números na quantidade a ser acrescentada.", vbApplicationModal, "Números"
TextBox2.Value = ""
TextBox2.SetFocus
Else
ant = TextBox1.Value
nov = TextBox2.Value
txtFax.Value = ant - nov
End If
Call Minmax
End Sub
Private Sub AtualizaRegistroCorrente()
lblNavigator.Caption = indiceRegistro - 1 & " de " & wsCadastro.UsedRange.Rows.Count - 1
lblMensagem.Caption = ""
End Sub
Sub locTeste2()
'converte a 1ªletra do texto digitado na combobox para maiúsculas
TextBox7.Text = StrConv(TextBox7.Text, vbProperCase)
Dim sRaz1 As String
Dim sName As String
Dim fimBase As String
Dim consulta As Long
Dim ShCadastro As Worksheet
'' Dim indiceRegistro As Long
sName = TextBox7.Value
If sName <> "" Then
'Application.ScreenUpdating = FalseAs Byte
'Limpar campos
Set ShCadastro = wsCadastro
'Consulta Dados Cadastro
ShCadastro.Activate
fimBase = Range("A60000").End(xlUp).Row
For consulta = 1 To fimBase
With ShCadastro
sRaz1 = .Cells(consulta, 2).Value 'Nome Cliente
If sName = sRaz1 Then
sNomeConfirma = sName
indiceRegistro = .Cells(consulta, 1).Value
Call CarregaRegistro
End If
End With
Next
End If
End Sub
Sub PreencherListView()
Dim lastRow As Long
Dim li As ListItem
Dim x As Long
Dim wsCadastro2 As Long
wsCadastro2 = Sheets("Calculo").Select
' Adiciona as colunas
With ListView1
.Gridlines = True
.View = lvwReport
'.FullRowSelect
.ColumnHeaders.Add Text:="ID", Width:=20
.ColumnHeaders.Add Text:="PRODUTO", Width:=60
.ColumnHeaders.Add Text:="DESCRIÇÃO DO PRODUTO", Width:=120
.ColumnHeaders.Add Text:="QTDE", Width:=30
.ColumnHeaders.Add Text:="PREÇO UN", Width:=50
.ColumnHeaders.Add Text:="P_TOTAL", Width:=45
.ColumnHeaders.Add Text:="LINHA DE NEGOCIO", Width:=60
.ColumnHeaders.Add Text:="QDTE ESTOQUE:=30"
End With
'...................................................................
'limpar
ListView1.ListItems.Clear
lastRow = Sheet1.Cells(Sheet1.Cells.Rows.Count, "a").End(xlUp).Row
' Adiciona itens
For x = 2 To lastRow
Set li = ListView1.ListItems.Add(Text:=Sheet1.Cells(x, "a").Value)
li.ListSubItems.Add Text:=Sheet1.Cells(x, "b").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "c").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "d").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "e").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "F").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "G").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "H").Value
li.ListSubItems.Add Text:=Sheet1.Cells(x, "I").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "J").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "K").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "L").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "M").Value
''li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "N").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "O").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "P").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "Q").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "R").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "S").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "T").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "U").Value
'li.ListSubItems.Add Text:=wsCadastro2.Cells(x, "V").Value
Next
'Me.TextBox1.SetFocus