Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ZecaLoteiro

Excluir Linha do Excel

Recommended Posts

Olá, preciso fazer um programa que verifica registros duplicados em uma planília do excel.

Peguei um exemplo, mas em VB 6, preciso de ajudar pra realizar em Vb.net

 

ficou assim:

CODE
Public Class Form1

Dim Excel As New Object

Dim X As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Excel = Excel.Application

With Excel.ActiveSheet

X = 3

While X < 10000

If .Cells(X, 2).Value = .Cells(X - 1, 2).Value Then

.Cells(X, 2).EntireRow.Delete()

Else

X = X + 1

End If

End While

End With

End Sub

End Class

Porém não funfa...

 

Ele dá o seguinte erro quando clico no botão:

 

Public member 'Application' on type 'Object' not found.

Alguém pode me ajudar ???!

Plz ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Enocntrei na web:

 

Imports Excel = Microsoft.Office.Interop.Excel

Public Class myExcel

  Public Sub RemoveLinhas(ByVal CaminhoArquivo As String)

	'Remove as 3 primeiras linhas da primeira planilha da pasta de trabalho

	Dim oWkb As Excel.Workbook

	oWkb = GetObject(CaminhoArquivo)

	oWkb.Application.Visible = True

	Dim oWks As Excel.Worksheet = oWkb.Worksheets(1)

	'Preenche alguns dados para testar

	oWks.Range("A1:A5").Value = "Teste linha"

	For i As Integer = 1 To 5

	  oWks.Cells(i, 2).value = i

	Next i

	'Exclui as três primeiras linhas

	oWks.Range("1:3").Delete()
  End Sub
End Class

Abraços...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não funciona...

 

coloquei a linha Imports Excel = Microsoft.Office.Interop.Excel

antes de tudo, porém ela fica sublinhada... e aparece

 

Warning 1 Namespace or type specified in the Imports 'Microsoft.Office.Interop.Excel' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. C:\NOTAS\Excel\Excel\Form1.vb 1 9 Excel

 

 

?! Sabe oq é isso ?

Valew

Compartilhar este post


Link para o post
Compartilhar em outros sites

Resolvido !

Thanx !!!!

 

CODE
Dim excel As Object = CreateObject("Excel.Application")

excel.Workbooks.Open(TextBox1.Text)

excel.Visible = True

X = NumericUpDown2.Value

While X < NumericUpDown1.Value

K = X - 1

If excel.ActiveSheet.Cells(X, 2).Value = excel.ActiveSheet.Cells(K, 2).Value Then

excel.ActiveSheet.Cells(X, 2).EntireRow.Delete()

Else

X = X + 1

End If

End While

excel.Visible = True

 

Valewws !

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.