Created
May 17, 2016 02:40
-
-
Save crclayton/513f0b79440f1ffba2fd659c8daa54e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'put the excel file, the image folder, and the script in the same folder | |
spreadsheetName = "Countries.xlsx" | |
imagesType = ".png" | |
imageNameColumn = "A" | |
imageColumn = "D" | |
imageWidth = 150 | |
Set objExcel = CreateObject("Excel.Application") | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set oImage = CreateObject("WIA.ImageFile") | |
directory = fso.GetParentFolderName(WScript.ScriptFullName) | |
Set objWorkbook = objExcel.Workbooks.Open(directory & "\" & spreadsheetName) | |
objExcel.Application.Visible = True | |
for i = 1 to objExcel.ActiveWorkbook.Worksheets(1).UsedRange.Rows.Count | |
imageName = objExcel.Cells(i, imageNameColumn).Value | |
imageFile = directory & "\" & imageName & imagesType | |
if imageFile <> "" and fso.FileExists(imageFile) then | |
oImage.LoadFile imageFile | |
with objExcel.Cells(i, imageColumn) | |
.AddComment " " | |
.Comment.Shape.Fill.UserPicture imageFile | |
.Comment.Shape.Width = imageWidth | |
.Comment.Shape.Height = oImage.Height * imageWidth/oImage.Height | |
end with | |
end if | |
next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment