Skip to content

Instantly share code, notes, and snippets.

@crclayton
Created May 17, 2016 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crclayton/513f0b79440f1ffba2fd659c8daa54e3 to your computer and use it in GitHub Desktop.
Save crclayton/513f0b79440f1ffba2fd659c8daa54e3 to your computer and use it in GitHub Desktop.
'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