使用excelmacros创buildfunction点

我有一个有趣的问题,我不确定。 我没有用力点,有一点擅长的macros观经验。 我发现了很多类似的问题,但没有一个适合这个法案。 我正在帮助我的本地慈善机构筹集资金,并需要一种方式来制作一种triva类游戏。 游戏将会以幻灯片的forms显示,所有的问题,select和答案都在Excel表格中。 它的铺设方式是每行一个问题,列是:问题,选项,答案和类别。

我已经很容易地pipe理了类别sorting,但现在我需要以某种方式创build幻灯片,以便问题是标题,选项是内容,然后下面的幻灯片是答案那个问题。 因此,每个问题创build两个幻灯片,一个问题和答案幻灯片。

示例行(|表示列):

这些是哪一个意大利雕塑家? | 米开朗基罗,丁托列托,达芬奇,加利洛| 米开朗基罗| 艺术

所以结果是标题“哪个是意大利雕刻家? 和内容a)米开朗基罗,b)tintoretto,c)da vinci,d)galilleo

下面的幻灯片简直就是“米开朗琪罗”

我设法弄清楚自己编写在Excelmacros。 这不是最好的解决scheme,但很容易遵循,可以由有这个问题的人修改。 仅供参考,我是这个问题的提问者,但我的电脑严重需要重新映像,我不能login堆栈溢出…哦。 这是我的代码,解决了这个问题。 请注意,所有的问题都按类别进行了sorting,所以我只是简单地改变了开始和结束循环控制variables,以便在保存并closures之前创build的新的ppts。 下面的代码可能包含从其他堆栈溢出问题中借用的代码,并被重用:

Sub CreatePowerPointQuestions() 'Add a reference to the Microsoft PowerPoint Library by: '1. Go to Tools in the VBA menu '2. Click on Reference '3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay 'First we declare the variables we will be using Dim newPowerPoint As PowerPoint.Application Dim activeSlide As PowerPoint.Slide Dim Question As String Dim Options As String 'comma separated list of options Dim Choices() As String 'split up options for printing Dim printOptions As String 'string to print in contents of slide Dim Answer As String Dim limit As Integer 'set question amount: limit = 5 'Look for existing instance On Error Resume Next Set newPowerPoint = GetObject(, "PowerPoint.Application") On Error GoTo 0 'Let's create a new PowerPoint If newPowerPoint Is Nothing Then Set newPowerPoint = New PowerPoint.Application End If 'Make a presentation in PowerPoint If newPowerPoint.Presentations.Count = 0 Then newPowerPoint.Presentations.Add End If 'Show the PowerPoint newPowerPoint.Visible = True 'Select worksheet and cells activate Worksheets("Sheet1").Activate 'Loop through each question For i = 1 To limit 'Add a new slide where we will paste the Question and 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 the variables to the cells Question = ActiveSheet.Cells(i, 1).Value Options = ActiveSheet.Cells(i, 2).Value Answer = ActiveSheet.Cells(i, 3).Value 'Split options into choices a,b,c,d based on comma separation Choices() = Split(Options, ", ") 'Formate printOptions to paste into 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 the title of the slide the same as the question for the options activeSlide.Shapes(1).TextFrame.TextRange.Text = Question 'Add answer slide and select it 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 to answer: activeSlide.Shapes(2).TextFrame.TextRange.Text = Answer 'Finished with a row (question) Next AppActivate ("Microsoft PowerPoint") Set activeSlide = Nothing Set newPowerPoint = Nothing End Sub 

我有一个商业PPT加载项,这种types的事情,但不幸的是不是这个确切的事情。

总的来说,您需要从包含两张幻灯片的PPT演示文稿开始,每个演示文稿都有“占位符”文本框…带有@ question @,@ answer @等文本的文本框。

该代码将:

获得数据的行数(即需要的Q&A幻灯片对的数量)

复制你的起始“模板”PPT文件,然后复制每个原始幻灯片n次,其中n =电子表格中的数据行数。

走下行数据,对于每一行,replace当前幻灯片中的@ question @文本,replace当前幻灯片中的选项,增加幻灯片计数器,将当前幻灯片中的@ answer @replace为当前幻灯片中的答案一排数据等等。

你可以用PPT或Excel写这个; 如果你熟悉VBA / Excel,我会在那里做的。