Salve, ho un problema col seguente programmino (sono alle primissime armi con vb.net), potete aiutarmi?
Questo è il codice...
' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Excel = Microsoft.Office.Interop.Excel
Public Class ScriptMain
' The execution engine calls this method when the task executes.
' To access the object model, use the Dts object. Connections, variables, events,
' and logging features are available as static members of the Dts class.
' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
'
' To open Code and Text Editor Help, press F1.
' To open Object Browser, press Ctrl+Alt+J.
Public Sub Main()
'
' Add your code here
'
'Cancella le prime 4 righe del file excel
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim i As Integer
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlApp.Visible = True
xlBook = xlApp.Workbooks.Open(Filename:="D:\testing3.xls")
xlSheet = CType(xlBook.ActiveSheet, Excel.Worksheet)
xlSheet.Visible = CType(True, Excel.XlSheetVisibility)
xlSheet.Rows.Range("A1", "A4").EntireRow.Delete()
'individua la prima riga vuota e esce dal ciclo, subito dopo la cancella
i = 1
While (Not IsNothing(xlSheet.Cells.Range("A" + CStr(i)).Value.ToString))
i = i + 1
End While
xlSheet.Cells.Range("A" + CStr(i)).EntireRow.Delete()
xlBook.Save()
xlApp.Quit()
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
Questo è l’errore che mi viene fuori quando lo eseguo:
vedere file allegato