mercredi 29 mai 2019

A teacher turned coder - need help generating random sheets that include strings, images and hopefully equations

The purpose of the workbook will be to randomly generate 5-10 questions for school children to attempt.

It will need a questions sheet and an answer sheet, I have already managed to find an appropriate one that randomly generates strings but as math questions get more complicated we need images and/or equations.

You will be seriously helping the education sector is you help us with this!

The code below is the closest thing I have found that will generate random images but means each question has to be screenshotted and put into the same folder.

An added complication is that this needs to work on school computers that has security that refrains from showing the file/folder directory so the directory needs to be defined as the folder the workbook is in.

Public Function PictureLookup(Value As String, Location As Range, Index As Integer)

Application.Volatile

Dim lookupPicture As Shape Dim sheetName As String Dim picTop As Double Dim picLeft As Double

sheetName = Location.Parent.Name

'Delete current picture with the same Index if exists For Each lookupPicture In Sheets(sheetName).Shapes If lookupPicture.Name = "PictureLookup" & Index Then lookupPicture.Delete End If Next lookupPicture

'Get position of cell calling the UDF picTop = Location.Top picLeft = Location.Left

'Add the picture in the right location Set lookupPicture = Sheets(sheetName).Shapes.AddPicture _ ("C:\Users\marks\Documents\Flags\" & Value & ".png", msoFalse, msoTrue, picLeft, picTop, -1, -1)

'change the picture name lookupPicture.Name = "PictureLookup" & Index

PictureLookup = ""

End Function




Aucun commentaire:

Enregistrer un commentaire