为什么用DIir文件遍历的时候显示错误

qq_35600277 2019-07-10 07:59:46
Sub 变幅()


Dim str As String
Dim x As Integer

dirs = Dir("E:\??????????????\????\1\00??????" & "\*.xlsx")

Do While dirs <> ""
Set xlsx = Workbooks.Open("E:\??????????????\????\1\00??????" & "\" & dirs)

Dim c, d, e, f As Integer
c = 7 '???????
d = 8 '????????
e = 9 '??С???
f = 10 '??С????
g = 1 '?????????????


r = 2
m = 2

Sheets.Add

Sheets(2).Cells(1, c) = xlsx.Sheets(1).Cells(1, 2)

Sheets(2).Cells(1, d) = "时间"
Do While xlsx.Sheets(1).Cells(r, 1) <> ""
Sheets(2).Cells(m, c) = xlsx.Sheets(1).Cells(r, 2)
Sheets(2).Cells(m, d) = Year(xlsx.Sheets(1).Cells(r, 1))


Do While Year(xlsx.Sheets(1).Cells(r, 1)) = Sheets(2).Cells(m, d) And xlsx.Sheets(1).Cells(r, 1) <> ""
If Sheets(2).Cells(m, c) >= xlsx.Sheets(1).Cells(r, 2) Then
Sheets(2).Cells(m, c) = Cells(m, c)
Sheets(2).Cells(m, d) = Cells(m, d)
Else
Sheets(2).Cells(m, c) = xlsx.Sheets(1).Cells(r, 2)
Sheets(2).Cells(m, d) = Year(xlsx.Sheets(1).Cells(r, 1))
End If
r = r + 1
Sheets(2).Cells(m, 11) = Cells(m, 7) - Cells(m, 9) '11??????
Loop
m = m + 1
Loop
m = 2
r = 2
Do While xlsx.Sheets(1).Cells(r, 1) <> ""
Sheets(2).Cells(m, e) = xlsx.Sheets(1).Cells(r, 2)
Sheets(2).Cells(m, f) = Year(xlsx.Sheets(1).Cells(r, 1))
Do While Year(xlsx.Sheets(1).Cells(r, 1)) = Cells(m, f) And xlsx.Sheets(1).Cells(r, 1) <> "" '?????????????
If Sheets(2).Cells(m, e) <= xlsx.Sheets(1).Cells(r, 2) Then
Sheets(2).Cells(m, e) = Cells(m, e)
Sheets(2).Cells(m, f) = Cells(m, f)
Else
Sheets(2).Cells(m, e) = xlsx.Sheets(1).Cells(r, 2)
Sheets(2).Cells(m, f) = Year(xlsx.Sheets(1).Cells(r, 1))
End If
r = r + 1
Loop
m = m + 1
Loop

xlsx.Close True


dirs = Dir
Loop



End Sub


显示错误为
过程调用或参数无效(错误 5)
2017/06/08

无法完成调用的某一部分。 此错误的原因和解决方案如下:
参数可能超出允许值的范围。 例如, Sin 函数只能接受特定范围内的值。 可以接受小于 2,147,483,648 的正参数,而 2,147,483,648 则会生成此错误。
检查参数允许的范围。
如果尝试调用在当前平台上无效的过程,也会出现此错误。 例如,有些过程仅对 Microsoft Windows 或 Macintosh 等有效。
检查平台特定的过程信息。
有关其他信息,选择有问题的项并按 F1(在 Windows 中)或 HELP(在 Macintosh 上)。
支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。
...全文
33 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,464

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧