PowerPoint Automation at Client side (using VBScript)


Description: Sometimes it is required to do COM automation at the client side based on the project requirements. Here is one such example that does the PowerPoint automation.

'Create the Power Point application
Set InitPowerPointObject = Createobject("PowerPoint.Application")
InitPowerPointObject.Visible = True

'Open the presentation
Set presentation = InitPowerPointObject.Presentations.Open( "Sample.ppt", False, True, True)           

InitPowerPointObject.Activate

'This code sets the values for the placeholders in the slide
'<LOGIN NAME> , <Date> and <Company> are the placeholders in the 'powerpoint slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select

slide.Shapes(1).TextFrame.TextRange.Replace "<LOGIN NAME>", "UserName"   
slide.Shapes(1).TextFrame.TextRange.Replace "<Date>", "Date"
slide.Shapes(1).TextFrame.TextRange.Replace  "<Company>", "CompanyName"

'Add title to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape = slide.Shapes.AddTitle()
heading = node.getElementsByTagName("Heading").Item(0).Text
shape.TextFrame.TextRange.Text = "Givens: " + heading
shape.TextFrame.TextRange.Font.Name = "Arial"
shape.TextFrame.TextRange.Font.Size = 32
shape.TextFrame.TextRange.Font.Color.RGB = RGB(0, 51, 153)
shape.TextFrame.TextRange.Font.Italic = False
shape.TextFrame.TextRange.Font.Bold = False

'Adding a TextBox control to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape = slide.Shapes.AddTextbox(1, 100, 100, 500, 400)
shape.TextFrame.TextRange.Text = "Name"
shape.TextFrame.TextRange.Font.Name = "Arial"
shape.TextFrame.TextRange.Font.Size = 20
shape.TextFrame.TextRange.Font.Color.RGB = RGB(178, 178, 178)
shape.TextFrame.TextRange.Font.Italic = False
shape.TextFrame.TextRange.Font.Bold = False

'Adding a Label control to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape = slide.Shapes.AddLabel(1, 100, 100, 15, 35)
With shape.TextFrame.TextRange
.Text = "change in size”
      With .Font
            .Name = "Times New Roman"
            .NameOther = "Times New Roman"
            .Size = 13
            .Bold = True
            .Italic = True
            .Underline = False
            .Shadow = False
            .Emboss = False
            .BaselineOffset = 0
            .AutoRotateNumbers = False
            .Color.SchemeColor = 2
            .Color.RGB = RGB(102, 102, 255)
      End With
End With

'Adding a Line to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape = slide.Shapes.AddLine(150, 30, 450, 30)
With shape
.Line.Visible = True
.Line.Weight = 1.25
.Line.DashStyle = 3
.Line.ForeColor.SchemeColor = 8
.Line.BackColor.RGB = RGB(255, 255, 255)
End With

'Adding TextEffect (Word Art) to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape = slide.Shapes.AddTextEffect(0, "Impact", "Arial Black", 16, msoFalse, msoFalse, 0, 250.5)
With shape
.Fill.Visible = True
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 255, 0)
End With

'Insert image to the slide
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
slide.Shapes.AddPicture "C:\\Sample.jpg",False,True, 100,100,500,60

'Manipulating tables in PowerPoint slides. The following code shows how 'to add a text to table cells.       
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
slide.Shapes(2).Table.Rows(1).Cells(1).Shape.TextFrame.TextRange.Text = "Row1, Cell1"
slide.Shapes(2).Table.Rows(1).Cells(2).Shape.TextFrame.TextRange.Text = "Row1, Cell2"

'Adding table to the slide and setting row height
Set slide = presentation.Slides(1)
presentation.Slides(1).Select
Set shape =   slide.Shapes.AddTable(1, 4, 80, 100,700,350)
Set row = shape.Table.Rows(1)
row.Height = 25