vba - Create power point using excel macro -
i have interesting problem unsure of. have not worked power point , have little excel macro experience. have found many similar issues mine none of them quite fit bill. helping local charity fund raiser , need way make triva sort of game. game displayed powerpoint, , questions, choices, , answers in excel sheet. way laid our 1 question per row, , columns are: question, options, answers , category.
i have managed category sorting quite easy enough, need somehow work creating power point slides in such way question title, options being content, , following slide answer question. therefore each question creates 2 slides, question , answer slide.
example row (| denote column):
which of these italian sculptor? | michelangelo, tintoretto, da vinci, galilleo | michelangelo | art
so result side title "which of these italian sculptor?" , content a) michelangelo, b) tintoretto, c) da vinci, d) galilleo
the following slide being "michelangelo"
i managed figure out coding myself in excel macro. it's not best solution, easy follow , can modified same issue. fyi asker of question, computer in serious need of reimage , can't log in stack overflow...o well. here code solved problem. please note of question sorted category prior changed start , end loop control variables make new ppts after saving , closing created ones. following code may contain code borrowed other stack overflow questions , repurposed:
sub createpowerpointquestions() 'add reference microsoft powerpoint library by: '1. go tools in vba menu '2. click on reference '3. scroll down microsoft powerpoint x.0 object library, check box, , press okay 'first declare variables using dim newpowerpoint powerpoint.application dim activeslide powerpoint.slide dim question string dim options string 'comma separated list of options dim choices() string 'split options printing dim printoptions string 'string print in contents of slide dim answer string dim limit integer 'set question amount: limit = 5 'look existing instance on error resume next set newpowerpoint = getobject(, "powerpoint.application") on error goto 0 'let's create new powerpoint if newpowerpoint nothing set newpowerpoint = new powerpoint.application end if 'make presentation in powerpoint if newpowerpoint.presentations.count = 0 newpowerpoint.presentations.add end if 'show powerpoint newpowerpoint.visible = true 'select worksheet , cells activate worksheets("sheet1").activate 'loop through each question = 1 limit 'add new slide paste question , options: newpowerpoint.activepresentation.slides.add newpowerpoint.activepresentation.slides.count + 1, pplayouttext newpowerpoint.activewindow.view.gotoslide newpowerpoint.activepresentation.slides.count set activeslide = newpowerpoint.activepresentation.slides(newpowerpoint.activepresentation.slides.count) 'set variables cells question = activesheet.cells(i, 1).value options = activesheet.cells(i, 2).value answer = activesheet.cells(i, 3).value 'split options choices a,b,c,d based on comma separation choices() = split(options, ", ") 'formate printoptions paste content printoptions = "a) " & choices(0) & vbnewline & "b) " & choices(1) & vbnewline & "c) " & choices(2) & vbnewline & "d) " & choices(3) activeslide.shapes(2).textframe.textrange.text = printoptions 'set title of slide same question options activeslide.shapes(1).textframe.textrange.text = question 'add answer slide , select newpowerpoint.activepresentation.slides.add newpowerpoint.activepresentation.slides.count + 1, pplayouttext newpowerpoint.activewindow.view.gotoslide newpowerpoint.activepresentation.slides.count set activeslide = newpowerpoint.activepresentation.slides(newpowerpoint.activepresentation.slides.count) 'set title: activeslide.shapes(1).textframe.textrange.text = "answer:" 'set contents answer: activeslide.shapes(2).textframe.textrange.text = answer 'finished row (question) next appactivate ("microsoft powerpoint") set activeslide = nothing set newpowerpoint = nothing end sub
Comments
Post a Comment