VBA下弹框打开excel文件并读取数据

Sub LoadExcelData()
    Dim wkbk As Workbook  '定义一个工作薄
    Dim myFileName As String '定义要读取的文件路径
    Dim dataRow  As Integer '定义数据的行
    Dim dataColumn As Integer '定义数据的列
    Dim rgRC As String '读取的单元格内容(dataRow,dataColumn)
    Dim arr(3 To 10, 1 To 9) As String '定义一个二维数组
   ' myFileName = Application.GetOpenFilename("EXCEL文件(*.xlsx), *.xls")  '浏览文件,如XX公司17年XX表.xls
    If myFileName = "False" Then  '如果按取消那么弹出对话框
        'MsgBox "请选择文件!", vbInformation, "取消"
    Else
    Set wkbk = Workbooks.Open(myFileName) '先打开要复制的文件
 
        wkbk.Activate '激活打开工作簿
                
        For dataRow = 3 To 10  '设置行的范围
            For dataColumn = 1 To 9   '设置列的范围
                Sheets("sheet1").Activate
                rgRC = Cells(dataRow, dataColumn)   '取得
              arr(dataRow, dataColumn) = Cells(dataRow, dataColumn)
           Next dataColumn
        Next dataRow

你可能感兴趣的:(VB/VBA)