Multiple Apps

Download daily wallpapers images directly from bing.com

Ease of Use

Easy

Version tested with

2010 

Submitted by:

boyatbox

Description:

Macro to download images from bing.com. It also set the downloaded images as desktop background. 

Discussion:

 

Code:

instructions for use

			

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

How to use:

  1. Open excel.
  2. Press Alt+F11 to bring up the VBA editor.
  3. Insert a new Module and paste the code.
 

Test the code:

  1. Press F5 to execute the macro.
 

Sample File:

BingWallpaper.zip 36.02KB 

Approved by mdmackillop


This entry has been viewed 36 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express