简体   繁体   English

运行时错误1004-打开工作簿超链接

[英]Run-time error 1004 - opening a workbook hyperlink

I am trying to write a simple code for looping through some .xls files from a Japanese site. 我正在尝试编写一个简单的代码来循环访问日语站点中的某些.xls文件。 While making the framework I run into a Runtime 1004 problem - www.e-stat...could not be found, yet the the files are available. 在制作框架时,我遇到了运行时1004问题-找不到www.e-stat ...,但是文件可用。 Here's the code. 这是代码。 If someone could tell me where I'm going wrong, that'd be splendid. 如果有人可以告诉我我要去哪里错,那真是太好了。 PS - I've tried looking for the answer everywhere on the internet. 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

Fully qualify the URL with the protocol and assign its handle to wb. 使用协议对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

I ran your code with the above modification and was able to open all 4 workbooks. 我使用上述修改运行了您的代码,并能够打开所有4个工作簿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM