dimv
10-20-2018, 10:30 AM
Hi,
I am new to VBA especially with powerpoint vba.
I am trying to insert excel cell range (i.e A1:A10 and B1:B10) to slides' Textbox1 and Textbox2, respectively.
With the below code (in ppt), i succeeded in inserting the excel values BUT i want, if possible, to modify the code in order to choose myself from which slide the input will start.
Assume that i have a presentation with 20 slides, and the start point i want to be slide 5 to 15.
Any ideas? thanks in advance
Sub GetDataFromExcel()
Dim I As Integer
Dim oXL As Object 'Excel.Application
Dim oWB As Object 'Excel.Workbook
Dim oSld As Slide
Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(FileName:="C:\Users\Infinity\Desktop\test1.xlsx")
'Assumes the active presentation has 20 slides.
For I = 1 To 20
Set oSld = ActivePresentation.Slides(I)
oSld.Shapes("TextBox1").TextFrame.TextRange.Text = oWB.Sheets("Sheet1").Range("a" & CStr(I)).Value
oSld.Shapes("TextBox2").TextFrame.TextRange.Text = oWB.Sheets("Sheet1").Range("b" & CStr(I)).Value
Next I
oWB.Close
oXL.Quit
Set oWB = Nothing
Set oXL = Nothing
End Sub
I am new to VBA especially with powerpoint vba.
I am trying to insert excel cell range (i.e A1:A10 and B1:B10) to slides' Textbox1 and Textbox2, respectively.
With the below code (in ppt), i succeeded in inserting the excel values BUT i want, if possible, to modify the code in order to choose myself from which slide the input will start.
Assume that i have a presentation with 20 slides, and the start point i want to be slide 5 to 15.
Any ideas? thanks in advance
Sub GetDataFromExcel()
Dim I As Integer
Dim oXL As Object 'Excel.Application
Dim oWB As Object 'Excel.Workbook
Dim oSld As Slide
Set oXL = CreateObject("Excel.Application")
Set oWB = oXL.Workbooks.Open(FileName:="C:\Users\Infinity\Desktop\test1.xlsx")
'Assumes the active presentation has 20 slides.
For I = 1 To 20
Set oSld = ActivePresentation.Slides(I)
oSld.Shapes("TextBox1").TextFrame.TextRange.Text = oWB.Sheets("Sheet1").Range("a" & CStr(I)).Value
oSld.Shapes("TextBox2").TextFrame.TextRange.Text = oWB.Sheets("Sheet1").Range("b" & CStr(I)).Value
Next I
oWB.Close
oXL.Quit
Set oWB = Nothing
Set oXL = Nothing
End Sub