请仔细体会一下:
Dim mydate As Date = Forms("余额明细").Controls("DateTimePicker1").Text
Dim ny As String = format( mydate,"yyyy-MM")
Dim Book As New XLS.Book(ProjectPath & "银行余额.xls")
If ny > "" AndAlso DataTables("余额明细").Find("年月 = '" & ny & "'") IsNot Nothing Then
messagebox.show("当月数据已导入","提示")
Return
End If
Dim id As Integer = -1
If DataTables("余额明细").DataRows.Count > 0 Then
id = DataTables("余额明细").Compute("Max([_Identify])")
End If
For i As Integer = 0 To Book.Sheets.Count -1
Dim a As String = Book.Sheets(i).Name
If a = ny Then
Dim mg As New Merger
mg.SourcePath = ProjectPath & "银行余额.xls"
mg.Format = "excel" '指定格式
mg.SourceTableName = "" & ny &"$" '指定要合并的表
mg.DataTableName = "余额明细" '指定接收数据的表
mg.Merge() '开始合并
DataTables("余额明细").ReplaceFor("年月", ny ,"[_Identify] > " & id)
DataTables("余额明细").Save()
Return
End If
Next
Messagebox.show("需导入的数据不存在!","提示")