- Sub sl ()
- 'Dim cc As CommonDialog
- On Error Resume Next
- cc.FileName = ""
- cc.DialogTitle = "选择要导入的文件"
- cc.Filter = "Microsoft Excel 2003(*.xls)|*.xls|Microsoft Excel 2007(*.xlsx)|*.xlsx"
- cc.ShowOpen
- If cc.FileName = "" Then
- Exit Sub
- Else
- Dim ExcelApp As Object
- Dim Workbooks As Object
-
- Set ExcelApp = CreateObject("Excel.Application")
- If Err Then
- MsgBox Err.Number & ":" & Err.Description '打开失败
- Exit Sub
- End If
- ExcelApp.Visible = True '显示Excel
- Set Workbooks = ExcelApp.Workbooks
- Workbooks.Open cc.FileName
- End If
- End Sub
|