PDA

View Full Version : Excel to Power Point



makako
04-02-2008, 08:10 AM
Hi, i have always worked VBA in excel only. Today I was trying to create a series of slides in ppt and to variate a single textbox. My Idea was using a database in excel filled with names. The macro was supposed to copy the initial slide and modify-insert a textbox with each name in my data. I started recording the macro in PPT and this is what I got


ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
With ActiveWindow.Selection.TextRange
.Text = "My Name"
With .Font
.Name = "Arial"
.Size = 44
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppTitle
End With
End With
ActiveWindow.Selection.Unselect
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).SlideIndex


but as I tried to create a variable "myVar as Range" Range was not an option. Is there a way to relate VBA code avaliable in Excel in ppt? thanks

Bob Phillips
04-02-2008, 08:52 AM
ARe you trying to drive this from Excel or from within PPT?

makako
04-02-2008, 09:03 AM
from ppt, but if i can make from excel it works for me

mdmackillop
04-02-2008, 10:04 AM
You need a reference to Excel

Something like

Sub Macro1()
'Set a reference to Microsoft Excel x.x Object Library
Dim wb As New Excel.Workbook
Dim rng As Excel.Range
Set wb = Workbooks.Open("C:\AAA\Test.xls")
Set rng = wb.Sheets(1).Range("A1:A2")
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
ActiveWindow.Selection.TextRange.Text = rng(1)

End Sub

makako
04-02-2008, 02:45 PM
The idea is to select a clean slide in ppt, run the macro, select the database, select the range an generate a presentation with # of slides as # of cells in range. I get errors in each of the excel sentences
PS I already created the reference to EXCEL 11, thanks mdmackillop


Sub SubSlides()
Dim lvSlide As Variant, lim As Integer
Dim wb As Excel.Workbook
Dim rng As Excel.Range

Set wb = Workbooks.Application.GetOpenFilename
Set rng = wb.Application.InputBox("Range", Type:=8)

For lim = 1 To rng.Cells.Count
ActiveWindow.Selection.Copy
ActiveWindow.View.Paste
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHoriz ontal, 258.625, 598.125, 249.5, 28.875).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue
ActiveWindow.Selection.TextRange.Text = rng(lim)
Next
End Sub