Excel経由でWin32APIを使ってファイルをダウンロードするVBScript

[wsh][vbs]

URLと保存先フォルダを指定する例

ExecuteExcel4Macroを使う

'--------------------------------------
'指定されたURLのファイルをダウンロード
'--------------------------------------
Sub SubDownLoad(strURL,saveFolder)

	Dim saveFilePath
	Dim wkFileName

	'保存するパスの編集
	wkFileName = split(strURL,"/")			
	saveFilePath = saveFolder & "\" & wkFileName(Ubound(wkFileName))

	Dim Application
	Dim CD
	Dim URL
	Dim Path
	Dim RC

	Set Application=CreateObject("Excel.Application")
	CD=CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("")
	Call Application.ExecuteExcel4Macro("CALL(""kernel32"",""SetCurrentDirectoryA"",""JC"","""&CD&"\..\"")")

	Path=saveFilePath	'Application.GetSaveAsFileName("*.*","すべてのファイル,*.*")
	If Path=False then
		'no work
	else 
		RC=Application.ExecuteExcel4Macro("CALL(""urlmon"",""URLDownloadToFileA"",""JJCCJJ"",0,"""&strURL&""","""&saveFilePath&""",0,0)")
		If RC Then
			MsgBox Join(Array(strURL,Path,Hex(RC)),vbLf),vbCritical,"失敗"
			Err.Raise &H80070000 Or (&HFFFF& And RC)
		Else
			MsgBox Join(Array(strURL,Path,RC),vbLf),vbInformation,"成功"
		End If
	End If


End Sub

ネタ元