Avatar of Rex
RexFlag for United States of America

asked on 

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

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.

Rex
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

        
        
        rs.MoveNext
    Loop
    rs.Close
    cn.Close
End Sub

Open in new window

PowerPoint-Error.jpg
Microsoft PowerPointMicrosoft AccessMicrosoft Word

Avatar of undefined
Last Comment
GrahamSkan
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Rex
Rex
Flag of United States of America image

ASKER

GrahamSkan:

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.
Avatar of Rex
Rex
Flag of United States of America image

ASKER

Thank you!

Rex
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo