3

私は、PowerPoint プレゼンテーションを作成するためのメトリックと「数のクランチ」データを追跡するための Access データベースを持っています。毎月約 40 件のプレゼンテーションを行いますが、その 98% はグラフです。

一度に 1 つずつクエリを実行し (SQL ステートメントを使用)、結果のデータを取得して Excel テンプレートにコピーします (この「テンプレート」でモック テーブルを作成したため、グラフは既に作成され、書式設定されています)。次に、グラフを次のようにコピーします。画像を PowerPoint テンプレートに。

そのため手作業が多い。

同じデータセット/テーブルに対して VBA を使用して Access で複数のクエリを実行するにはどうすればよいですか (四半期ごと、月ごと、地域ごと、州ごと、サイトごとに売上を行う必要があり、これらはすべて上位 5 の集計であるため、グラフの理由は)、次に、結果のデータを特定の Excel ワークブックに送信し、何をどのセル範囲に入れるかを定義しますか?

すべてのデータを Excel に取り込んでグラフを作成する準備ができたら、Excel (activeworksheet) からグラフを取得し、クアッド ビュー レイアウトの画像として PowerPoint に貼り付ける VBA はありますか?

Access to PowerPoint アプローチで同じことを行い、Excel を切り取ることはできますか?

私はせいぜい初心者です。

4

3 に答える 3

4

Excel を使用する必要はまったくありません。レポートで MS Access Charts を使用し、いくつかの VBA コードを使用して Powerpoint に直接挿入します。ここにすでに例があります

グループ内のグラフを生成する場合、つまり、グループ内のグラフを使用してレポートを設計する場合、レポートを実行すると多数のグラフが作成されます。

これらのグラフのそれぞれを取得して 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

これにより、レポート内のすべてのグラフが検索されます。グラフがグループ内にある場合は、InsertGraphGroupToPPt 関数を呼び出します。

ここでの秘訣は、同じ基本グラフが複数回あることを知っていることですが、異なるデータが入力されています。したがって、Powerpoint で行う必要があるのは、ベース グラフを PowerPoint スライドに n 回貼り付けることです。ここで、n はグループの数であり、グラフのクエリ プロパティを更新します。

例えば

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
于 2009-07-29T18:59:51.040 に答える
1

あなたは初心者なので、おそらくタスクをいくつかのパーツに分割し、パーツを 1 つずつ自動化する必要があります。各ステップには利点があり (時間の節約など)、学習しながら学習できます。

特定の情報 (バージョンなど) が不足しているため、特定の推奨事項を作成することは困難です。そうは言っても、スプレッドシートが毎月自動更新され、Access から Excel にデータをカット アンド ペーストする必要がないように、Excel テーブルをアクセス クエリにリンクすることがおそらく最初のステップとして適切でしょう。このリンクはすべて Excel 内で行うことができます。

Excel 2007 を使用している場合は、リボンの [データ] をクリックし、[アクセスから] をクリックします。

于 2009-05-17T14:56:47.083 に答える
0

あなたが求めているのはたくさんの仕事です:

VBAを介して、Excel(AccessからのExcelアプリケーション操作)を開き、グラフを更新する必要があります(範囲操作、データ更新)。権限がある場合は、ピボットグラフをAccessデータに接続し、貼り付けないことをお勧めします。ワークブック、それにもかかわらず、私はそれが不可能であった十分な状況にありました。次に、PowerPointプレゼンテーションを開き、ExcelからPowerPointにコピーする必要があります。私はこれらすべてを実行し、これを実行するためのマクロを(VBA経由で)作成することでどれだけの作業を節約できるかを知っています。それはたくさんのコードです。

于 2009-05-18T17:12:52.563 に答える