MS Access的PowerPoint自动化…查询到图表?

大家好! 我想知道有没有人可以帮助我这个…

我有一个Access数据库,我用它来跟踪我工作的指标和“数字紧缩”数据,我用它来构buildPPT演示文稿。 我通常每个月要做大约40个百分点,他们是98%的图表。

现在,我一次运行一个查询(使用SQL语句),获取结果数据并将其复制并粘贴到excel模板中(我简单地在这个“模板”中做了一个模拟表格,以便图表已经被构build和格式化),然后将图表作为图片复制到ppt模板中。

所以有很多手工的工作,这一点不会那么糟糕,只有一个月的时间我才能有这样的口气。

所以…..我怎么能运行多个查询在Access VBA在同一个数据集/表(我必须按季度,按月,按地区,按州,按地点…和所有这些是Top5聚合,因此图表的原因),然后将结果数据发送到特定的Excel工作簿,同时定义什么进入什么单元格范围?

如果我把所有的数据都转换成excel,并准备好图表,那么是否有一些VBA将excel(activeworksheet)中的图表作为四维视图布局中的图片粘贴到PowerPoint中?

我可以使用Access to PowerPoint的方法做同样的事情,并一起切出excel吗?

充其量我是一个新手! 任何和所有的帮助,提示,build议非常感谢!

根本不需要使用Excel! 在报告中使用MS Access Charts和一些VBA代码直接将它们放入Powerpoint。 这里已经有一个例子

一个“疑难杂症”是如果你在一个组中生成图表,即你使用一个组内graphics来devise报表 – 所以当你运行报表时,你会得到大量的图表。

掌握这些图表并把它们放到Powerpoint中是有点棘手的,但是这里有一些代码会照顾它。 这在Access 2003中工作

'Loop through all the controls in this report and pickout all the graphs For Each c In pReport.Controls 'Graphs initially appear to be in an Object Frame If TypeOf c Is ObjectFrame Then 'Check the Class of the object to make sure its a Chart If Left$(c.Class, 13) = "MSGraph.Chart" Then 'Check if this graph must be cloned (required if the graph is in a group in the MS Access report) If Not IsGraphToBeCloned(pReport.Name, c.ControlName) Then InsertGraphToPptSlide c, "", pReport.Name Else InsertGraphGroupToPpt pReport.Name, c End If End If End If Next 

这将查找报告中的所有graphics,如果graphics在一个组中,则我们调用InsertGraphGroupToPPt函数。

这里的诀窍是,我们知道我们有多个相同的基本图 – 但填充不同的数据。 因此,在Powerpoint中,您需要做的是将基础graphics粘贴到幻灯片幻灯片n次 – 其中n是组的数量,然后更新graphics查询属性

例如

 Function UpdateGraphInPowerpoint(sql As String, OrigGraph As ObjectFrame, Groups As dao.Recordset, GroupName As String, ReportName As String) As Boolean //Copyright Innova Associates Ltd, 2009 On Error GoTo ERR_CGFF On Error GoTo ERR_CGFF Dim oDataSheet As DataSheet Dim Graph As Graph.Chart Dim lRowCnt, lColCnt, lValue As Long, CGFF_FldCnt As Integer Dim CGFF_Rs As dao.Recordset Dim CGFF_field As dao.Field Dim CGFF_PwrPntloaded As Boolean Dim lheight, lwidth, LLeft, lTop As Single Dim slidenum As Integer Dim GraphSQL As String Dim lGrpPos As Long 'Loop thru groups Do While Not Groups.EOF 'We want content to be added to the end of the presentation - so find out how many slides we already have slidenum = gPwrPntPres.Slides.Count OrigGraph.Action = acOLECopy 'Copy to clipboard slidenum = slidenum + 1 'Increment the Ppt slide number gPwrPntPres.Slides.Add slidenum, ppLayoutTitleOnly 'Add a Ppt slide 'On Error Resume Next 'Ignore errors related to Graph caption gPwrPntPres.Slides(slidenum).Shapes(1).TextFrame.TextRange.Text = ReportName & vbCrLf & "(" & Groups.Fields(0).Value & ")" 'Set slide title to match graph title gPwrPntPres.Slides(slidenum).Shapes(1).TextFrame.TextRange.Font.Size = 16 gPwrPntPres.Slides(slidenum).Shapes.Paste 'Paste graph into ppt from clipboard Set Graph = gPwrPntPres.Slides(slidenum).Shapes(2).OLEFormat.Object Set oDataSheet = Graph.Application.DataSheet ' Set the reference to the datasheet collection. oDataSheet.Cells.Clear ' Clear the datasheet. GraphSQL = Replace(sql, "<%WHERE%>", " where " & GroupName & " = '" & Groups.Fields(0).Value & "'") Set CGFF_Rs = ExecQuery(GraphSQL) CGFF_FldCnt = 1 ' Loop through the fields collection and get the field names. For Each CGFF_field In CGFF_Rs.Fields oDataSheet.Cells(1, CGFF_FldCnt).Value = CGFF_Rs.Fields(CGFF_FldCnt - 1).Name CGFF_FldCnt = CGFF_FldCnt + 1 Next CGFF_field lRowCnt = 2 ' Loop through the recordset. Do While Not CGFF_Rs.EOF CGFF_FldCnt = 1 ' Put the values for the fields in the datasheet. For Each CGFF_field In CGFF_Rs.Fields oDataSheet.Cells(lRowCnt, CGFF_FldCnt).Value = IIf(IsNull(CGFF_field.Value), "", CGFF_field.Value) CGFF_FldCnt = CGFF_FldCnt + 1 Next CGFF_field lRowCnt = lRowCnt + 1 CGFF_Rs.MoveNext Loop ' Update the graph. Graph.Application.Update DoEvents CGFF_Rs.Close DoEvents Groups.MoveNext Loop UpdateGraphInPowerpoint = True Exit Function End Function 

既然你是一个新手,也许你应该把任务分解成几部分,一次一个地自动化。 每一步都将提供好处(即节省时间),您可以随时学习。

根据缺乏具体的信息(什么版本等)很难提出具体的build议。 也就是说,或许一个好的第一步是将Excel表链接到访问查询,以便电子表格可以每月自动更新一次,而不必将Access中的数据剪切并粘贴到Excel中。 你可以在Excel中完全链接。

如果您使用Excel 2007,请单击function区中的“数据”,然后单击“从访问”。

你问的是很多工作:

通过VBA,你必须打开Excel(Excel应用程序从Access操作),更新你的图表(范围操作,数据更新),如果你有权利,那么我build议让你的透视图连接到Access数据,而不是粘贴到工作簿,但我已经处于足够的情况下,这是不可能的。 然后,您将不得不打开您的PowerPoint演示文稿并从Excel复制到PowerPoint。 我已经完成了所有这些工作,并且知道通过创build一个macros(通过VBA)可以节省多less工作。 这是很多代码。