|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 导入数据()
- Dim u%, i%, o%, ans As Variant, wb As Workbook, fileNameObj As Variant, p As Integer
- Dim aFile As Variant '数组,提取文件名fileName时使用'打开文件对话框返回的文件名,是一个全路径文件名,其值也可能是False,因此类型为Variant
- Dim fullName As String
- Dim fileName As String '从FileName中提取的路径名
- ans = MsgBox("确认保存数据并继续?", vbOKCancel + vbDefaultButton1)
- If ans = vbOK Then
- 'Application.Calculation = xlManual
- fileNameObj = Application.GetOpenFilename("Excel 文件 (*.xls),*.xls") '调用Windows打开文件对话框
- If fileNameObj <> False Then '如果未按“取消”键
- aFile = Split(fileNameObj, "")
- fileName = aFile(UBound(aFile)) '数组的最后一个元素为文件名
- fullName = aFile(0)
- For p = 1 To UBound(aFile) '循环合成全路径
- fullName = fullName & "" & aFile(p)
- Next
- Else
- MsgBox "请选择文件"
- End
- End If '得到Excel全路径
-
- Set wb = Workbooks.Open(fullName)
- For o = 1 To wb.Sheets.Count
- With wb.Sheets(o)
- For u = 4 To 40
- For i = 3 To 40
- If .Cells(u, i) <> "" And .Cells(u, 2) <> "" And .Cells(3, i) >= 1 And .Cells(3, i) <= 31 Then
- arr = Array(.Cells(3, i).Value, Sheets(o).Name, .Cells(u, 2).Value, .Cells(u, i).Value) [出现要求对象,求大神斧正]
- Cells(Rows.Count, 1).End(xlUp).Row.Offset(1, 0).Resize(1, 4) = arr
- End If
- Next
- Next
- End With
- Next
- End If
- 'Application.Calculation = xlAutomatic
- End Sub
复制代码
|
|