Sub LoadExcelData()
Dim wkbk As Workbook '定义一个工作薄
Dim myFileName As String '定义要读取的文件路径
Dim rgA1 As String'定义要读取的单元格A1
Dim rgB10 As String'定义要读取的单元格B10
myFileName = Application.GetOpenFilename("EXCEL文件(*.xls), *.xls") '浏览文件,如XX公司08年XX表.xls
If myFileName = "False" Then '如果按取消那么弹出对话框
MsgBox "请选择文件!", vbInformation, "取消"
Else
Set wkbk = Workbooks.Open(myFileName) '先打开要复制的文件
wkbk.Activate‘激活打开工作簿
Sheets("Sheet1").Activate ‘如果提示下标越界,可以使用Sheets(1).Activate
rgA1 = Cells(1, 1) '取得A1
Sheets("Sheet2").Activate
rgB10 = Cells(10, 2)'取得B10
wkbk.Close False '关闭工作薄
Cells(2, 1) = rgA1’给目标格赋值A2
Cells(3, 1) = rgB10’给目标格赋值A3
MsgBox "文件导入成功,请保存该文件!"
' End If
End If
End Sub