我正在尝试编写一个简单的代码,用于循环来自日语站点的一些.xls文件。在制作框架时遇到运行时1004问题 - www.e-stat ...无法找到,但文件可用。这是代码。如果有人能告诉我哪里出错了,那就太棒了。 PS - 我试过在互联网上到处寻找答案。
Sub automate()
Dim wb As Workbook
Dim filepath As String
Thswb = ThisWorkbook.Name
'Worksheets("data").Activate
'Dim namearray As Integer
Dim MyArray(1 To 4) As Integer
MyArray(1) = 0
MyArray(2) = 1
MyArray(3) = 2
MyArray(4) = 7
For i = 1 To UBound(MyArray)
Workbooks.Open "www.e-stat.go.jp/SG1" & "/estat/XlsdlE.do?sinfid=00002723131" & MyArray(i)
'Do stuff
'In progress
ActiveWorkbook.Close
Next i
End Sub
答案 0 :(得分:0)
使用协议对URL进行完全限定,并将其句柄分配给wb。
Sub automate()
Dim wb As Workbook
Dim filepath As String, Thswb As String, i As Integer
Thswb = ThisWorkbook.Name
'Worksheets("data").Activate
'Dim namearray As Integer
Dim MyArray(1 To 4) As Integer
MyArray(1) = 0
MyArray(2) = 1
MyArray(3) = 2
MyArray(4) = 7
For i = 1 To UBound(MyArray)
Set wb = Workbooks.Open("http://www.e-stat.go.jp/SG1" & "/estat/XlsdlE.do?sinfid=00002723131" & MyArray(i))
With wb
'Do stuff
'In progress
End With
wb.Close
Set wb = Nothing
Next i
End Sub
我使用上述修改运行了您的代码,并且能够打开所有4个工作簿。