I am looking to do this also, however trying to avoid reporting services seems quite tricky. In the mean time, and apologies as I know this is an old thread but I have this which is VBA code run from a PowerPoint to populate a table with the results from
a SQL query.
New Sub Routine:
Dim conn
Dim rs
Dim cs As String
Dim query As String
Dim row As Integer
Public Details
Dim icol As Integer, irow As Integer, minW As Single
Sub MYPERSONAL_SQLServer_Connection()
'** Check connection and only run if connection is closed
If IsObject(cn) = False Then
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=mymachine\mySQLEXPRESS; Initial Catalog=mydatabase; user id=myuser; password=mypword"
'** Open Con
cn.Open
'** SQL Script goes here
Qry = "Select col1, "
Qry = Qry & "col2, "
Qry = Qry & "col3, "
Qry = Qry & "From mysqltable "
'** Open the query and run throught the records
Set RecSet = cn.Execute(Qry, adAsyncConnect)
'** Start from the beginning & count the records
RecSet.MoveFirst
col = RecSet.Fields.Count
i = 0
Do Until RecSet.EOF = True
i = i + 1
RecSet.MoveNext
Loop
row = i
RecSet.MoveFirst
'** Remove and cleanup previous Powerpoint table
With ActivePresentation.Slides(1)
For Each Shp In ActivePresentation.Slides(1).Shapes
Shp.Delete
Next Shp
End With
'** Build the Powerpoint table
With ActivePresentation.Slides(1).Shapes.AddTable(row + 1, col)
ReDim textShapes(0 To 2)
i = 0
For Each Shape In ActivePresentation.Slides(1).Shapes
If Shape.HasTable Then
Shape.Name = "prbTable"
End If
Next Shape
End With
r = 2
c = 1
'** Build the rows per field item #Details = Details & Field & "|"
Set oPPTShape = ActivePresentation.Slides(1).Shapes("prbTable")
With oPPTShape.Table
.Cell(1, 1).Shape.TextFrame.TextRange.Text = "Col1"
.Cell(1, 1).Shape.TextFrame.TextRange.Font.Size = 8
.Cell(1, 1).Shape.TextFrame.TextRange.Font.Bold = True
.Cell(1, 1).Shape.TextFrame.HorizontalAnchor = msoAnchorCenter
.Cell(1, 2).Shape.TextFrame.TextRange.Text = "Col2"
.Cell(1, 2).Shape.TextFrame.TextRange.Font.Size = 8
.Cell(1, 2).Shape.TextFrame.TextRange.Font.Bold = True
.Cell(1, 2).Shape.TextFrame.HorizontalAnchor = msoAnchorCenter
.Cell(1, 3).Shape.TextFrame.TextRange.Text = "Col3"
.Cell(1, 3).Shape.TextFrame.TextRange.Font.Size = 8
.Cell(1, 3).Shape.TextFrame.TextRange.Font.Bold = True
.Cell(1, 3).Shape.TextFrame.HorizontalAnchor = msoAnchorCenter
End With
While Not RecSet.EOF
For Each Field In RecSet.Fields
If Field <> "" Then oPPTShape.Table.Cell(r, c).Shape.TextFrame.TextRange.Text = Field
oPPTShape.Table.Cell(r, c).Shape.TextFrame.TextRange.Font.Size = 8
c = c + 1
Next
c = 1
r = r + 1
RecSet.MoveNext
Wend
End If
Set cn = Nothing
'MsgBox ActivePresentation.PageSetup.SlideWidth
'MsgBox ActivePresentation.PageSetup.SlideHeight
With oPPTShape
.Height = 150
.Width = 750
.Left = 19
.Top = 89
.Table.Columns(2).Width = 57
End With
End Sub
I can't remember where I got the basics for this so sorry I can't post the thanks but I adjusted some for my own purposes to retrieve data. This is one set to one slide. I am in the process of trying to have an active Module to execute new slide creation
with executed query results.
Anyway, only 5 years late, but if anyone is interested.