For some reason the following Macro won’t work:
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
I get a run-time error ’52’ on line (“Bad file name or number”):
If Dir(FilePath & FileName) = Empty Then
Funny enough it did work once. And when location is ‘C:\’ it works and I don’t get an error. Weird stuff guys.
Any help would be greatly appreciated.
Opening a file from a file system is entirely different from downloading it over HTTP.
The simplest agnostic way is to simply use
Workbooks.Openwhich allows HTTP URIs;(You will need to remove
Dir()as thats for file systems only)