Jump to content
Fórum Script Brasil
  • 0

Dúvida Script


vini85

Question

Galera,

Estou com o seguinte erro:

Erro em tempo de execução '1004':

O método 'Range do objeto' _Global' falhou

Sinceramente não consigo encotrar o erro...

Segue o meu script:

Option Explicit

'RA = REGISTRO ATUAL
'NR = NUMERO TOTAL DE REGISTROS
'OP = OPERAÇÃO
Dim RA As Integer, NR As Integer, OP As String

Private Sub CBt_backup_Click()
    ActiveWorkbook.SaveCopyAs (TBx_caminho.Text)
    TBx_caminho = ""
    TBx_caminho.SetFocus
End Sub

Private Sub MultiPage1_Change()

End Sub

Private Sub UserForm_Activate()
            LControle
            Atribuir
            CBx_Tipo.AddItem "Corda"
            CBx_Tipo.AddItem "Sopro"
            CBx_Tipo.AddItem "Percussão"
End Sub

Private Sub LControle()
            RA = Range("RA")
            NR = Range("NR")
            OP = Range("OP")
End Sub

Private Sub GControle()
            Range("RA") = RA
            Range("OP") = OP
End Sub

Private Sub CBt_Primeiro_Click()
            RA = 1
            GControle
            Atribuir
End Sub

Private Sub CBt_Anterior_Click()
            RA = RA - 1
            GControle
            Atribuir
End Sub

Private Sub CBt_Proximo_Click()
            RA = RA + 1
            GControle
            Atribuir
End Sub

Private Sub CBt_Ultimo_Click()
            RA = NR
            GControle
            Atribuir
End Sub

Private Sub Atribuir()
            Dim Linha As Integer
            If NR = 0 Then
               Linha = RA + 2
            Else
               Linha = RA + 1
            End If
            TBx_Codigo = Sheets("Dados").Cells(Linha, 1)
            TBx_Instrumento = Sheets("Dados").Cells(Linha, 2)
            CBx_Tipo = Sheets("Dados").Cells(Linha, 3)
            TBx_Marca = Sheets("Dados").Cells(Linha, 4)
            TBx_Preco = Sheets("Dados").Cells(Linha, 5)
            TBx_Quantidade = Sheets("Dados").Cells(Linha, 6)
            TBx_Observacoes = Sheets("Dados").Cells(Linha, 7)
            Lbl_Operacao = OP & "..."
            Lbl_Apontador = RA & " / " & NR
            Operacao
            Navegacao
End Sub

Private Sub Navegacao()
            CBt_Primeiro.Enabled = (RA > 1 And OP = "Navegando")
            CBt_Anterior.Enabled = (RA > 1 And OP = "Navegando")
            CBt_Proximo.Enabled = (RA < NR And OP = "Navegando")
            CBt_Ultimo.Enabled = (RA <> NR And OP = "Navegando")
End Sub

Private Sub Operacao()
            CBt_Incluir.Enabled = (OP = "Navegando")
            CBt_Alterar.Enabled = (OP = "Navegando" And RA > 0)
            CBt_Excluir.Enabled = (OP = "Navegando" And RA > 0)
            CBt_Cancelar.Enabled = (OP = "Incluindo" Or OP = "Alterando")
            CBt_Consultar.Enabled = (OP = "Navegando" And NR > 1)
            CBt_Gravar.Enabled = (OP = "Incluindo" Or OP = "Alterando")
            CBt_Sair.Enabled = (OP = "Navegando")
            CBt_Imprimir.Enabled = (OP = "Navegando")
End Sub

Private Sub CBt_Incluir_Click()
            OP = "Incluindo"
            GControle
            RA = NR + 1
            Atribuir
            Fra_Dados.Enabled = True
            TBx_Codigo.SetFocus
End Sub

Private Sub CBt_Alterar_Click()
            OP = "Alterando"
            GControle
            Atribuir
            Fra_Dados.Enabled = True
            TBx_Codigo.SetFocus
End Sub

Private Sub CBt_Excluir_Click()
            If MsgBox("Confirma a exclusão?", vbYesNo + vbQuestion, "Confirmação") = vbYes Then
               Sheets("Dados").Rows(RA + 1).Delete
               If RA = NR Then
                  RA = RA - 1
                  GControle
               End If
               CBt_Cancelar_Click
            End If
End Sub

Private Sub CBt_Cancelar_Click()
            LControle
            OP = "Navegando"
            GControle
            Atribuir
            Fra_Dados.Enabled = False
End Sub

Private Sub CBt_Consultar_Click()
            Frm_Consulta.Show
            LControle
            Atribuir
End Sub

Private Sub CBt_Gravar_Click()
            If MsgBox("Confirma a operação?", vbYesNo + vbQuestion, "Confirmação") = vbYes Then
               Sheets("Dados").Cells(RA + 1, 1) = TBx_Codigo
               Sheets("Dados").Cells(RA + 1, 2) = TBx_Instrumento
               Sheets("Dados").Cells(RA + 1, 3) = CBx_Tipo
               Sheets("Dados").Cells(RA + 1, 4) = TBx_Marca
               Sheets("Dados").Cells(RA + 1, 5) = TBx_Preco
               Sheets("Dados").Cells(RA + 1, 6) = TBx_Quantidade
               Sheets("Dados").Cells(RA + 1, 7) = TBx_Observacoes
               GControle
               CBt_Cancelar_Click
            End If
End Sub

Private Sub CBt_Sair_Click()
  Unload Me
End Sub

Private Sub CBt_Imprimir_Click()
           Sheets("Dados").PrintOut
End Sub

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...