1

由于某种原因,以下宏不起作用:

Sub ExtractDataTest()


    Dim FilePath$, Row&, Column&, Address$


 'change constants & FilePath below to suit
     '***************************************
    Const FileName$ = "Dxo.xlsx"
    Const SheetName$ = "Open"
    Const NumRows& = 50
    Const NumColumns& = 20
    FilePath = ("http://enhanced1.sharepoint.hx.com/teams/")
     '***************************************


    DoEvents
    Application.ScreenUpdating = False
        If Dir(FilePath & FileName) = Empty Then
        MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
        Exit Sub
    End If
    For Row = 1 To NumRows
        For Column = 1 To NumColumns
            Address = Cells(Row, Column).Address
            Cells(Row, Column) = GetData(FilePath, FileName, SheetName, Address)
            Columns.AutoFit
        Next Column
    Next Row
    ActiveWindow.DisplayZeros = False
End Sub




Private Function GetData(Path, File, Sheet, Address)
    Dim Data$
    Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
    Range(Address).Range("A1").Address(, , xlR1C1)
    GetData = ExecuteExcel4Macro(Data)
End Function

我在线收到运行时错误“52”(“错误的文件名或编号”):

If Dir(FilePath & FileName) = Empty Then

有趣的是它确实工作过一次。当位置为“C:\”时,它可以工作并且我没有收到错误。奇怪的东西家伙。

任何帮助将不胜感激。

4

1 回答 1

1

从文件系统打开文件与通过 HTTP 下载文件完全不同。最简单的不可知论方法是简单地使用Workbooks.Open允许 HTTP URI 的方法;

Set wb = Workbooks.Open(FilePath & FileName)

(您只需要删除Dir()文件系统)

于 2012-12-20T13:56:23.210 回答