Way back in November, I received this email from Tom, a senior researcher at the Center for Learning Innovation in Australia.
I’ve been developing & have published spreadsheet applications for teachers for some time now. In particular, I have animations, adventure scenarios etc that can be used to create games for the classroom. I need to promote these so teachers eventually try these and use them. … Perhaps you could post some of these on your site.
What a noble cause, I thought. So I wrote back to him and invited him to share his files along with a guest article. Tom acted quick and emailed me his article and Excel workbooks by Thanksgiving day. I was too lazy and got lost in the flow of things. But now, I am very very glad to feature his work.
There are so many valuable tricks, ideas and powerful concepts buried in his workbook. I encourage everyone to play with his file (you need to enable macros) so that you can learn a thing or two. If you are a teacher, feel free to use the files to make your classroom teaching even more awesome.
What can you do with a spreadsheet? by Tom Benjamin

The spreadsheet was the original ‘must-have app’ that started the PC revolution because it allowed non-programmers to create loops. It is often overlooked in an era of countless cute free online calculators and interactivities. But few of the latter are easily deconstructed and customised to fit specific classroom needs, let alone being dressed in period costume to become a historical set or adventure cockpit for a an edu-game.
Now that Excel has incorporated graphic tools and form controls it is no longer ‘the boring old uncle’ of software. Its appearance can be as exciting as whatever graphic image you import into it. Its interactivity is as exciting as the context you give it in terms of setting the quest or adventure.
The accompanying spreadsheets cover a range of classroom applications. As demo’s they are intended to give you ideas rather than being a ‘finished product’ resource –ie- you need to look at the formulae to see how it works then change the content to fit your own purpose. These are available as free Creative Commons resources so you may deconstruct and re-purpose to your heart’s content. The main classes of spreadsheet covered here are as follows:
Graphics: Sheets 1-6
The clip art, vector drawing tools and general formatting provisions in Excel allow it to be used as a PowerPoint slide. Without even using formulae, graphic images can be used to hide clues, and elements can be moved around the screen, such as peeking under the ‘rocks’ in the dungeon example. This basic use fits in well with interactive white boards (IWBs). Vector drawing offers capabilities beyond the bitmap imagery in much IWB software. One effective technique is to use the huge library of special fonts such as scientific, i-Ching, Zodiacal, Roman Numeral, Arabic, WebDings and other symbols. Thus, a clue or answer can come up as an image rather than a number.

Although PowerPoint is better-equipped to display animated scenes, videos, sound, and animated .gifs, Excel can display changing frames merely by clicking between sheets manually, allowing complex visual animation. Software is readily-available to de-construct videos, animations and complex simulation modelling output into individual frames. Simple animation can be created by putting such a sequence of images on separate worksheets. The presenter can then scroll through these rapidly either via a form control button or merely hitting the next worksheet tab. This works especially well for full-screen graphics.
Charts: Sheets 7 -24
Charts can be dressed up with graphic borders, colours, and image elements so that they are scarcely recognisable as graphs. The ‘rocket cockpit’ example shows how steering wheels, instrument control panels, and simulated instruments of all types can be created merely by surrounding them with graphic borders. In primary school these might merely be used as visual display items, for instance the flickering torches and spider web in the Dungeon example. Or these could be linked to a formula so that they only flickered or appeared when a wrong answer was given. Setting the mood for such games falls outside the spreadsheet realm but the graphic images used in an adventure game can be set as backgrounds or images in a spreadsheet. Thus, pictures of the various decks of the ship in a pirate adventure could become background images. The player would then work from sheet to sheet inputting words or numbers which would make something happen in the scene, such as the sail rising or the cannon shooting, all of which could take place within a chart by converting its bar graph or pie graph elements to picture backgrounds.
Slider formula controls: Sheets 7-24
In addition to text and numerical input, Excel allows sliders and spinners to control cells. These cells can then trigger events in the sheet. Especially useful for vivid graphical display are protractors made from pie charts as attached. Contour maps are versatile as they can create pictures using colours and image-fills. The attached examples show clues being generated by moving a slider.
More complex animations can be created by linking the picture-filled elements of a chart with ‘0-1’ ‘on-off-switch’ formulae. Examples are shown in the attachments. Again, these are limited only by their quality and imaginative use. Full-blown videos or animations created in other software can be exported to individual frames. Moving a slider can then call up the individual frames. A ‘virtual puppet’ and ‘news desk’ are shown as examples. It would be more commonly applied to illustrating a concept difficult to show with live-action such as the satellite fly-by. The latter could be linked to formulae showing the distance from Earth, velocity etc. These values can be taken from more sophisticated software rather than trying to calculate them with Excel formulae.

Again, the imagination of the presenter is key in that a quick visual simulation may not need to be exact to illustrate a classroom concept. It need only be as good as what might have formerly been portrayed by a sweep of the chalk on a blackboard. The big advantage of the spreadsheet over the chalkboard may be less its imagery than the fact that it can be saved, improved and re-used rather than wiped after the session.
Artificial intelligence and interactive: Sheets 24-27
Human judgment of complex rating decisions can be simulated merely using in-built mathematical formulae without resorting to logical formulae, much less programming. Pearson correlations are a built-in function and other matching formulae are easily programmed. The attached example uses the Spearman Rank-Order formula to score the similarity of a launch sequence against an ‘ideal’ sequence-order. Research has consistently shown that such seemingly ‘simple’ formulae can reliably outperform even highly-trained professionals if given a good set of answer criteria.
The value of such artificial intelligence models in the classroom is that they can interact with the learner and that they can be seen to be fair and unbiased provided the criteria for judgment are made explicit to the learner. The Bidding Game and Balloon Launch Sequence examples demonstrate such uses. They are easy to create as they use built-in functions so are limited only by their imaginative use.

If we want our programme to really seem lifelike we can add language interaction. This is important if learners are supposed to be typing in queries like “how tall is…?” or “who is…?” but decide to play around and input irrelevant and irreverent comments. Excel has a range of logical ‘lookup’ expressions that can be combined with formulae to create responses.
The number of cells was a limitation in earlier spreadsheets but the 65536 rows now available allows for at least some limited language response. The random number function refreshes with each entry so that a more life-like interaction can be achieved by linking a rand() function to a cell such that the value changes to an integer drawing randomly from a set of response words/phrases. The final worksheet example ‘the crashing bore’ shows what can be done using commands to parse the input string, a look-up to identify key words, another lookup to match responses to those words, and a random function to prevent the same answers reappearing. More complex interaction could be achieved by constraining user input to specific questions like “how much”, “where is” etc, using weightings, and pattern-correlating against the input string. Graphics can make the ‘chatterbot’ answer-machine interaction seem more life-like or appropriate (like HAL9000 the computer from 2001: A Space Odyssey).
Download the Excel Files
Please click here to download the Excel Workbook for Teachers [this file is 9MB, so give it sometime to download]
Also, Tom made a simple Excel skills test. Click here to download and test your Excel skills.
Thank you Tom
A big thanks to Tom for sharing this valuable work with all of us. I have already learned some good tricks from his workbook (creating image slide-show thru charts+scroll-bar, running formulas on click of button, using contour charts etc.). I am sure you too will find some interesting areas of application or learn some valuable things by examining his workbook.
If you like this workbook, please say thanks to Tom.
Also, if you are teacher, please share your experience of using Excel in teaching effectively.

















38 Responses to “Time to showoff your VBA skills – Help me fix ActiveSheet.Pictures.Insert snafu”
I tried your code with 2003, it works.
But, I know Addpicture does not take URLs anymore with 2007 onwards, perhaps its the same with picture.insert as well.
http://support.microsoft.com/kb/928983/en-us
The above link gives the solution as "picture fill in a shape such as a rectangle".
Tried to recreate this, but it worked fine for me. I just took the image of the error you showed in the post. Is there more info that can narrow this down a bit?
Don't know if this helps?
http://www.theserverside.com/discussions/thread.tss?thread_id=47101
Hi
Not sure if this is what you're after, but I just tried this
Sub Macro1()
ActiveSheet.Pictures.Insert("http://www.google.co.uk/intl/en_uk/images/logo.gif").Select
End Sub
Tied a button to it on the sheet and it seems to work; hope this helps a little
Ian
@All.. the issue is in Excel 2007. In 2003 ActiveSheet.Pictures.Insert seems to work fine. Unfortunately, I have design this in Excel 2007.. that is why I posted it here..
v2
Sub Macro1()
Set n = ActiveSheet.Pictures.Insert("http://www.google.co.uk/intl/en_uk/images/logo.gif")
With Range("c12")
t = .Top
l = .Left
End With
With n
.Top = t
.Left = l
End With
End Sub
Ian
That didn't come out very well. This positions at c12, so can change easily:
Sub Macro1()
Set n = ActiveSheet.Pictures.Insert("http://www.google.co.uk/intl/en_uk/images/logo.gif")
With Range("c12")
t = .Top
l = .Left
End With
With n
.Top = t
.Left = l
End With
End Sub
Works OK in 2007
Ian
The above codes work fines to my EXCEL 2007. Thanks.
Chandoo:
Try 'ActiveSheet.Pictures.Insert'
With ActiveSheet.Pictures.Insert("C:\Example.png")
.Left = ActiveSheet.Range("A1").Left
.Top = ActiveSheet.Range("A1").Top
End With
activesheet.pictures.insert "C:\Documents and Settings\Jon Peltier\Desktop\2007 stuff\insert_charts_2007.png"
Works for me in 2003 SP3 and in 2007 SP2.
Check the URL, and make sure you have internet connectivity.
What also works, and is newer (pictures.insert was supposedly deprecated in '97):
activesheet.shapes.addpicture "C:\Documents and Settings\Jon Peltier\Desktop\2007 stuff\insert_charts_2007.png", false, true, 200,200,100,100
Unfortunately you must specify dimensions (the last four arguments) and you don't necessarily know them. But the picture size is still related back to the original picture size, so you could use scaleheight and scalewidth to fix this.
Chandoo: I just re-read your post.
The code I posted works for me. However, I'm using a local picture. If you try to add a picture from the web, this won't work.
I remember solving this problem before by adding a rectangle shape first, then using the Shapes.AddPicture method to get a picture from the web.
I'll find that code and post it here.
Some more updates... The code "ActiveSheet.Pictures.Insert (path)" works fine in Excel 2007 at home. Strange it failed miserably on my work laptop. Do you think this has got something to do with SP2 of MS Office 2007 or something like that?
@Ian, Jon: Thanks for the code snippets. I guess I will use my home installation of excel to do this.
Chandoo:
Try this on your work laptop:
Sub test()
ActiveSheet.Shapes.AddShape msoShapeRectangle, 50, 50, 100, 200
ActiveSheet.Shapes(1).Fill.UserPicture _
"http://www.datapigtechnologies.com/images/dpwithPig6.png"
End Sub
FYI:
http://support.microsoft.com/kb/928983/en-us
I didn't mean to post code with a local file, because both approaches worked with an internet image as well. This is in Excel 2007 SP2.
activesheet.pictures.insert "http://peltiertech.com/images/2009-07/col_area_noblanks.png"
Jon: Looks like I have SP1 on my client machine! I wasn't paying attention.
Just checked my home computer where I have SP2, and you're right...looks like they fixed it.
I didn't even bother testing in SP1, though I could if anyone cares enough.
I'm afraid I don't have a solution, but I find it remarkable that after attaining a certain status in the Excel world, Chandoo does not need to post on an Excel discussion forum to get help for an Excel problem. Instead, he posts on his blog and all the gurus come rushing to his help.
Isn't Web 2.0 great?
Teylyn - I saw Chandoo's tweet first, and followed the link back to his blog.
@Mike.. thank you. I have seen the fill rectangle solution before posting the query here. For that matter, I have also tried the solution of embedding a browser control on a spreadsheet. both of these seemed a bit extreme. That is why I have asked it here.
But I guess I will end up using it if I had to build this in work laptop.
@Teylyn: I have thought of posting this in a forum. (Unfortunately I have not been to any excel group in the last 5 years. Last time I was active was when I built a jave based excel sheet construction solution using POI.HSSF classes of Apache... ) After searching for a few hours, I found several forum posts where others had same problem and the solution recommended (using .left and .top parameters) is not working for me. Incidentally most of these solutions are from a certain Jon Peltier 😛
I thought may be the problem is interesting for fellow blog readers. So I posted it here.
Hi,
Adapting the code in the question,
[code]
Sub InsPicture()
pPath = "http://chandoo.org/images/pointy-haired-dilbert-excel-charts-tips.png"
With ActiveSheet.Pictures.Insert(pPath)
.Left = Range("a1").Left
.Top = Range("a1").Top
End With
End Sub
[/code]
Seems to work fine
Looks like it was a problem in 2007 up to SP1, which was corrected in SP2.
@Jon.. seems like the case. I just checked the version at work laptop. it is 12.0.6331.5000 (SP1).
Thank you so much every one. I really appreciate your time and suggestions in solving this.
Glad to help. I couldn't understand why something so straightforward wasn't working.
Hi All
Is there a way of inserting a motion clip eg animated gif or swf or flv?
Thks
You can insert animated GIFs by inserting them in a browser control through VBA. For other types of movies, I can guess you can insert them as clip art.
I WANT THE INSERT PICTURE BY USING COADING
so currently i was struggling same as you, chandoo, with the insert picture method in excel 2007/10 from an url and came along your thread here.
so i re-designed the code on the addshape method as mike was suggesting it and all of the sudden it works just fine.
thanks alot to you guys, you were a great help
a big salut from switzerland
Hi guys,
I need help copying and pasting an image with the path in a cell.
I leave the code.
And thank you very much!
Sub Copiarimg()
Dim pic As Picture
With ActiveSheet
Set pic = .Pictures.Insert(Range("f2").Value)
With .Range("e9:g22")
pic.Top = .Top
pic.Left = .Left
pic.Width = .Width
pic.Height = .Height
End With
End Sub
I've played around with the approaches in these comments, and the code below is what I've come up with. The ImagePath can be a local file or a URL. As Jon mentioned above, the trick is to set an arbitrary value for the width and height, then call the ScaleWidth and ScaleHeight methods afterward to reset the picture to its original size. Once the LockAspectRatio property is set, you can change the picture width and the height will automatically scale (or vice-versa).
Sub AddPictureToRange(TopLeftCellAddress As String, ImagePath As String)
Dim pic As Shape
Dim l As Single, t As Single
Dim temp As Single
l = Me.Range(TopLeftCellAddress).Left
t = Me.Range(TopLeftCellAddress).Top
temp = 10# ' arbitrary value
Set pic = Me.Shapes.AddPicture(ImagePath, msoFalse, msoTrue, l, t, temp, temp)
pic.ScaleHeight 1#, msoTrue
pic.ScaleWidth 1#, msoTrue
pic.LockAspectRatio = msoTrue
End Sub
I need some help with inserting pictures. I have an excel file with a column of item numbers next to this row I want to insert a picture of this item. The pictures are coded with the item number so I tried to insert it with one of the codes above:
Sub InsPicture()
pPath = "http://img.bricklink.com/P/80/55236.gif"
With ActiveSheet.Pictures.Insert(pPath)
End With
End Sub
That worked but I need to do that for every row separtly.
So I tried in the code
pPath = "http://img.bricklink.com/P/80/"&Text(a1;"#")&".gif"
But that gives errors.
Anybody ideas?
Hi Nicholas, I used your solution in a related problem in Excel 2003 and it worked flawlessly..thank you!
Hi Mike Alexander,
Your solution with some changes was helpful in my problem in XL 2007, thanks.
Hi,
thanks all. In addition, I had a problem with multiple pictures inserting (every new picture replaced the prior one). I've changed it a bit, may be helpful..
Sub test()
ActiveSheet.Shapes.AddShape msoShapeRectangle, 50 , 50, 100, 200
ActiveSheet.Shapes(1).Fill.UserPicture _
"http://www.datapigtechnologies.com/images/dpwithPig6.png"
ActiveSheet.Shapes(1).Copy
ActiveSheet.Paste
End Sub
Try this instead:
Sub test()
ActiveSheet.Shapes.AddShape msoShapeRectangle, 50 , 50, 100, 200
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.UserPicture _
"http://www.datapigtechnologies.com/images/dpwithPig6.png"
End Sub
Thanks to everyone, this thread has been very helpful. However, image inserting still doesn't work quite as expect for me.
While I can get a picture inserted into an Excel 2010 worksheet using either:
1) ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.UserPicture...
2) ActiveSheet.Pictures.Insert(pPath), and
3) Shapes.AddPicture...
unfortunately the images all insert with a display size determined not by the actual pixel dimensions of the image but by the dpi resolution.
So for example, if I insert two copies of the exact same 600x600 pixel image, one with a 300dpi resolution and the other with 72dpi, they display at vastly different sizes on screen.
While this might be intended behaviour for Excel in order to maintain a WSYWIG printing layout, I actually need a way to insert the image based on the the actual pixel dimesnsions and ignoring the dpi resolution.
Any help appreciated.
Thanks
Kez
Not doing an intentional bump, but realised I posted in rely to one of the repsonses here instead of to the main thread, so reposting.
=====
Thanks to everyone, this thread has been very helpful. However, image inserting still doesn’t work quite as expected for me.
While I can get a picture inserted into an Excel 2010 worksheet using any of the below methods:
1) ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.UserPicture....
2) ActiveSheet.Pictures.Insert(pPath), and
3) Shapes.AddPicture....
unfortunately the images all insert with a display size determined not by the actual pixel dimensions of the image but by the dpi resolution.
So for example, if I insert two copies of the exact same 600×600 pixel image, one with a 300dpi resolution and the other with 72dpi, they display at vastly different sizes in Excel on screen.
While this might be intended behaviour for Excel in order to maintain a WYSIWYG printing layout, I actually need a way to insert the images based on the the actual pixel dimesnsions and ignoring the dpi resolution.
Any help appreciated.
Thanks
Kez
Well, answered my own question 🙂
For those who might be interested, you can use this function:
Public Function GetPicDims(strFilePath As String, strFileName As String) As String
GetPicDims = CreateObject("Shell.Application").Namespace((strFilePath)). _
ParseName(strFileName).ExtendedProperty("Dimensions")
End Function
to get the dimensions of the image you want to insert. Then you can parse the return string and use the width and height values to add a rectangle shape of the appropraite size, like:
ActiveSheet.Shapes.AddShape msoShapeRectangle 50, 50, iWidth, iHeight
which you then fill with the picture:
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.UserPicture "c:\temp\test.jpg"
This way the picture gets inserted using the pixel dimensions and the (print) resolution gets ignored.
If desired, the GetPicDims function can be made more generic to get other ExtendedProperties.
Regards
Kez