' ------------------------------------------------------------------------------------ ' ImportFromExcel.vbs ' Import a list of picture from a Microsoft Excel sheet. ' In this demo, the Excel sheet is assumed to have a header line with the following ' columns: ' File name, Size, Quality, Comment, City/State ' The file name is just the base file name of the picture, pictures are assumed to be ' located in the sBaseFolder folder. ' ------------------------------------------------------------------------------------ Option Explicit ' Change the following two constants to suit your needs Const ExcelFilename = "D:\WINDOWS\SDK\MyAlbum\axTest\ImportFromExcel.xls" Const sBaseFolder = "M:\Images\Voyages\Magagascar_2004\Photos01\" Const xlNormal = -4143 '(&HFFFFEFD1) Const ForReading = 1, ForWriting = 2 app.ClearTrace dim alb, i, sFileName, sSize, sQuality, sComment, sCity, pic ' The current album contains the orginal (without dots) world map picture set alb = app.GetCurrentAlbum ' The Excel file contains a list of pictures to import in the current album dim xl, xls, sheet app.Trace "Reading Excel file...", -1, TRACE_INFORMATION set xl = CreateObject("Excel.Application") xl.Visible = True xl.WindowState = xlNormal xl.Visible = True ' Open the Excel sheet in read-only mode Set xls = xl.Workbooks.Open(ExcelFilename, 0, True) set sheet = xls.ActiveSheet i = 2 ' Skip header on first line Do sFileName = sheet.Cells(i, 1) if sFileName = "" Then Exit Do sSize = sheet.Cells(i, 2) sQuality = sheet.Cells(i, 3) sComment = sheet.Cells(i, 4) sCity = sheet.Cells(i, 5) app.Trace " Picture #" & i-1 & ":" & vbTab & sFileName & vbTab & sComment & vbTab & sCity set pic = alb.AddPicture( sBaseFolder & sFileName ) if pic is Nothing then app.Trace "Caution: cannot find picture '" & sFileName & "'", 255, TRACE_WARNING else pic.sComment = sComment pic.SetCustomField "City", sCity end if i = i + 1 Loop ' Close Excel set xls = nothing xl.Quit set xl = nothing alb.redraw app.Trace "Done !", -1, TRACE_GREENDOT