|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
有两个excel文件:运行时错误1004.xlsm(代码所在文件)
2018年表.xls(这个文件放在D盘根目录)
代码运行时出错,请问为什么不对?
应该怎么写才能把“2018年表.xls”的某个工作表的数据存到数组中?
- Option Explicit
- Public x As Integer
- Public path9 As String
- Sub assignment() '全局变量赋值
- x = ThisWorkbook.Sheets(2).Range("$d$1").Value
- path9 = ThisWorkbook.Sheets(2).Range("$d$9").Value
- End Sub
- '判断路径的文件是否存在
- Function IsFileExists(ByVal filePath As String) As Boolean
- If Dir(filePath, 16) <> Empty And filePath <> "" Then
- IsFileExists = True
- Else
- IsFileExists = False
- End If
- End Function
- Sub test()
- Call assignment '全局变量赋值
-
- If (Not IsFileExists(path9)) Then
- MsgBox "文件不存在!"
- Exit Sub
- End If
-
-
- With GetObject(path9)
-
- <span style="background-color: yellow;"> y = .Sheets(x - 1).Cells(Rows.Count, "c").End(xlUp).Row '报错</span>
- brr = .Sheets(x - 1).Range("a9:k" & y).Value
- .Close flase
-
- End With
-
- End Sub
复制代码
运行时错误1004.rar
(33.09 KB, 下载次数: 3)
|
|