Private 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
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1
Sub downloadBingImages()
Dim arrayCountry
Dim blnYesNo As Boolean
Dim strImageLocation As String
Dim oResp As String
Dim vWebFile As String
Dim objShell As Object
Dim objFSo As Object
Dim oXMLHTTP As Object
Set objShell = CreateObject("Shell.Application")
objShell.minimizeAll
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
arrayCountry = Array("en-AU", "en-CA", "zh-CN", "de-DE", "fr-FR", "ja-JP", "en-NZ", "en-UK", "en-US")
For Each country In arrayCountry
For dt = 0 To 1
vWebFile = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=" & dt & "&n=1&nc=1361652262588&mkt=" & country
strFolderPath = CurDir & "BingImages"
oXMLHTTP.Open "GET", vWebFile, False
oXMLHTTP.Send
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop
oResp = oXMLHTTP.responsetext
If oResp = "null" Then
Exit For
End If
t1 = Split(oResp, """url"":""")
t2 = Split(t1(1), """,""urlbase"":""")
imageURL = "http://www.bing.com" & t2(0)
t3 = Split(imageURL, "/")
t4 = t3(UBound(t3))
t5 = Split(t4, "_")
f = t5(0) & ".jpg"
If Not objFSo.FolderExists(strFolderPath) Then
objFSo.CreateFolder (strFolderPath)
End If
If Not objFSo.FileExists(strFolderPath & f) Then
URLDownloadToFile 0, imageURL, strFolderPath & f, 0, 0
strImageLocation = strFolderPath & f
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, strImageLocation, SPIF_UPDATEINIFILE
End If
Next
Next
blnYesNo = MsgBox("Download completed." & vbCrLf & "Open folder ? ", vbYesNo, "Download completed")
If blnYesNo = True Then
objShell.Open strFolderPath
End If
End Sub
|