I Have a Word VBA Macro That Fills a Table. I Need to Convert it to PowerPoint VBA

Posted on 2011-10-10
Last Modified: 2012-05-12
I have a Word VBA Macro That I use to Fill a Table in Word by Pulling Data from an Access Database.

I have the same need to fill a table in Powerpoint by pulling from an Access Table.

The Code is below, it works in WORD, but When I try to Execute it in PowerPoint, I get an error, shown below. Can Somebody please tell me what I'm doing wrong? Thanks.

Option Explicit

Sub FillTable()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strConn As String
    Dim Doca As Document
    Dim para As Paragraph
    Dim rng As Range
    Dim strDateText As String
    Dim tbl As Table
    Dim rw As Word.Row
    Set Doca = ActiveDocument
     Set cn = New ADODB.Connection
    cn.Provider = "Microsoft.ACE.OLEDB.12.0"
    cn.Open "P:\KO Quality\KO Reporting\KO Weekly Reporting Data\Current Reporting Database\KO Quality Master 2008 Linked.accdb"

    Set rs = New ADODB.Recordset
    rs.Open "L2CAR_KOJ_Wood_Table", cn, adOpenDynamic, adLockOptimistic, adCmdTable
    Set tbl = Doca.Tables.Add(Doca.Bookmarks("\EndOfDoc").Range, 1, 5)
    tbl.Cell(1, 1).Range.Text = "Activity Type"
    tbl.Cell(1, 2).Range.Text = "Number"
    tbl.Cell(1, 3).Range.Text = "Start Date"
    tbl.Cell(1, 4).Range.Text = "Status"
    tbl.Cell(1, 5).Range.Text = "Defect Code"

    Do Until rs.EOF
        Set rw = tbl.Rows.Add
        rw.Cells(1).Range.Text = rs.Fields("Activity Type").Value
        rw.Cells(2).Range.Text = rs.Fields("Number").Value
        rw.Cells(3).Range.Text = rs.Fields("Start Date").Value
        rw.Cells(4).Range.Text = rs.Fields("Status").Value
        rw.Cells(5).Range.Text = rs.Fields("Defect Code").Value

End Sub

Open in new window

Question by:Rex85
    LVL 76

    Accepted Solution

    You need to set a reference (in VBA, Tools/References) to the Microsoft Active Data Objects Library

    Author Comment


    Thank you. (That was your code by the way.)

    I also need some clean up on the PowerPoint Object Model vs the Word Object Model, so I may need to ask an additional follow up question or two.

    Author Closing Comment

    Thank you!

    LVL 76

    Expert Comment

    I thought that it might be. I have recently taken to using DocA for the Active document.


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    In a previous video Micro Tutorial here at Experts Exchange (, I explained how to get a free, one-month trial of Office …

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now