URLを指定してファイルをダウンロードする

こちらのページを参考にしています。

Yahoo!のトップのロゴをダウンロードするには、以下のようなプログラムになります。

Visual Basic:
  1. 'URLDownloadToFile API from URLMON.
  2. Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
  3. "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
  4. szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
  5.  
  6. Sub test()
  7.     Dim strURL As String
  8.     Dim strFNAME As String
  9.     Dim returnValue
  10.  
  11.     strURL = "http://k.yimg.jp/images/top/sp/logo.gif"
  12.     strFNAME = "c:\yahoologo.gif"
  13.     returnValue = URLDownloadToFile(0, strURL, strFNAME, 0, 0)
  14.  
  15. End Sub

これでCドライブのルートにyahoologo.gifという名前でダウンロードされます。

VBAのお勉強 まとめへ戻る

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 simple blog いろいろ勉強中 Suffusion theme by Sayontan Sinha