'文件打开窗口操作 Public CommonDialog1Open As System.Windows.Forms.OpenFileDialog Dim intErrNum As Short CommonDialog1Open.FileName = "" CommonDialog1Save.FileName = "" CommonDialog1Open.Filter = "EXCEL | *.xls" CommonDialog1Save.Filter = "EXCEL | *.xls" CommonDialog1Save.OverwritePrompt = True CommonDialog1Open.ShowDialog() CommonDialog1Save.FileName = CommonDialog1Open.FileName intErrNum = Err.Number If intErrNum <> Windows.Forms.DialogResult.Cancel Then '或者写成下面的方式 'If OpenDialog.ShowDialog() = DialogResult.OK Then System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor txtExcelName.Text = CommonDialog1Open.FileName System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default End If Excel操作,可能参照中要增加excel类 Dim oExcel As Object Dim oBook As Object Dim oSheet As New Object Dim WSheetCount As Integer oExcel = CreateObject("Excel.Application") oBook = oExcel.Workbooks.Open(txtExcelName.Text, ReadOnly:=True) WSheetCount = oExcel.ActiveWorkbook.sheets.count For i = 1 To WSheetCount ’对Sheet1进行操作 If oBook.Worksheets.Item(i).name() = “Sheet1”Then oSheet = oExcel.ActiveWorkbook.Sheets(WSheet) Exit For End If Next ’通过行列号对单元格进行操作 oSheet.Cells(intRow, intColumn).Value oExcel.Application.DisplayAlerts = False oExcel.Application.Quit() oSheet = Nothing oBook = Nothing oExcel = Nothing