Dear All,
I am new to VBA programmining and for the first time trying to export excel data to powerpoint. The code I have compiled from sources on the web is as follows but does not work.
Sub CreateSlides()
'Step 1: Declare your variables
Dim PP As PowerPoint.Application
Dim oSl As PowerPoint.Slide
Dim oSh As PowerPoint.Shape
'Dim PPPres As PowerPoint.Presentation
'Dim PPSlide As PowerPoint.Slide
'Dim SlideTitle As String
'Step 2: Open PowerPoint and create new presentation
Set PP = New PowerPoint.Application
Set PPPres = PP.Presentations.Add
PP.Visible = True
ActivePresentation.Slides(1).Copy
Set oSl = ActivePresentation.Slides.Paste(ActivePresentation.Slides.Count + 1)
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:\users\CABS\desktop\WeeklyReturn.xlsm")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Dim sCurrentText As String
Dim Slidenum As Integer
Set WS = OWB.Worksheets("Master")
Dim i As Long
'Loop through each used row in Column A
For i = 1 To WS.Range("A65536").End(xlUp).Row
'Copy the first slide and paste at the end of the presentation
ActivePresentation.Slides(1).Copy
Set oSl = ActivePresentation.Slides.Paste(ActivePresentation.Slides.Count + 1)
sCurrentText = WS.Cells(i, 1).Value
'------------
'Slidenum = 1
oSl.Select
Set oSh = oSl.Shapes("Table1")
Sheets("Sheet1").Activate
oPPTShape.Table.Cell(i, 1).Shape.TextFrame.TextRange.Text = sCurrentText
'oPPTShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2).Text
'oPPTShape.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1, 3).Text
'oPPTShape.Table.Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2, 1).Text
'oPPTShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2, 2).Text
'oPPTShape.Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2, 3).Text
'--------------------------
' find each shape with "@COL1@" in text, replace it with value from worksheet
' For Each oSh In oSl.Shapes
' Make sure the shape can hold text and if is, that it IS holding text
' If oSh.HasTextFrame Then
' If oSh.TextFrame.HasText Then
' ' it's got text, do the replace
' With oSh.TextFrame.TextRange
'.Replace "@COL1@", sCurrentText
'End With
' End If
' End If
' Next
Next
End Sub
Request help
Bookmarks