感觉楼主这样的代码很不严谨。
这样试试:
Dim g As String = "d:\date\"
Dim r As String = e.Form.Controls("TextBox1").Value
Dim rr As String = ".xls"
If FileSys.FileExists(g & r & rr) Then '如果文件已经存在
Dim Book As New XLS.Book(g & r & rr) '打开模板
Dim Sheet As XLS.Sheet
For i as Integer = 0 to Book.Sheets.Count - 1 '判断来源表是否存在
if Book.Sheets(i).Name = r Then
Dim mg As New Merger
mg.SourcePath = "" & g & r & rr & ""
mg.Format = "excel"
mg.SourceTableName = "订单$"
mg.DataTableName = "订单"
mg.Merge()
End If
Next
End If
[此贴子已经被作者于2010-7-4 0:20:49编辑过]