Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Open URL For Input

Anyone know a way to use Open For Input on a file from the Internet?

Dim oURL As String
oURL = "http://finance.yahoo.com/d/quotes.csv?s=JPYUSD=X&f=sl1d1t1&e=.csv"
Open oURL For Input As #1

That returns error "Bad file name or number."

Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Open URL For Input

I didn't figure out any way to use Open/For Input directly on a URL, but I
did figure out how to download the CSV file from a URL, save it to a
temporary folder, read from it and then delete it, all in the background.

The first part is used at module level to declare references to an external
procedures in a dynamic-link library (DLL).

Public Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Sub RatesWebQuery()

Dim oSymbol As String
Dim oDate As String
Dim oTime As String
Dim oRate As Double
Dim oLocalFile As String
Dim oURL As String
Dim oReturnValue As Long
Dim oFSO As Scripting.FileSystemObject

Set oFSO = CreateObject("Scripting.FileSystemObject")

oLocalFile = Environ("TMP") & "\quotes.csv"
oURL = "http://finance.yahoo.com/d/quotes.csv?s=JPYUSD=X&f=sl1d1t1&e=.csv"

oReturnValue = URLDownloadToFile(0, oURL, oLocalFile, 0, 0)

If oReturnValue < 0 Then
If MsgBox("Problem downloading.") < 1 Then Exit Sub
Else
Open oLocalFile For Input As #1
Input #1, oSymbol, oRate, oDate, oTime
Close #1
oFSO.DeleteFile (oLocalFile)
End If

MsgBox oRate

End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ON OPEN VBA Code input incorrectly now excel sheet wont open mmartin New Users to Excel 1 February 16th 11 11:33 PM
how do i open file for input Jac Excel Discussion (Misc queries) 3 December 3rd 07 03:47 AM
open for input vba help chadkiser Excel Discussion (Misc queries) 0 March 5th 07 10:00 PM
Open (website) for Input? Joey Lichtenstein[_3_] Excel Programming 2 April 17th 06 03:56 AM
open an input screen cityfc Excel Programming 1 March 20th 06 02:01 AM


All times are GMT +1. The time now is 07:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"