I am looking for help with PowerPoint 2007 and using activex to help me create a PowerPoint that uses a special *.POT theme file as its base.
More specifically, I am calling the COM object from Matlab. Here is the code outline:
Code:
h = actxserver('PowerPoint.Application')
h.Visible = 1;
Presentation = h.Presentation.Add
blankSlide = Presentation.SlideMaster.CustomLayouts.Item(7)
Slide1 = Presentation.Slides.AddSlide(1,blankSlide)
Slide2 = Presentation.Slides.AddSlide(1,blankSlide);
figure;
plot(1:10)
print('-dpng','-r150','c:\temp\test1.png')
figure;
image(ceil(64*rand(20,20)))
print('-dpng','-r150','c:\temp\test2.png')
Image1 = Slide1.Shapes.AddPicture('c:\temp\test1.png','msoFalse','msoTrue',100,20,500,500)
Image2 = Slide2.Shapes.AddPicture('c:\temp\test2.png','msoFalse','msoTrue',100,20,500,500)
Title1 = Slide1.Shapes.AddTextbox('msoTextOrientationHorizontal',200,10,400,70)
Title1.TextFrame.TextRange.Text = 'plot(1:10)'
Title2 = Slide2.Shapes.AddTextbox('msoTextOrientationHorizontal',200,10,400,70)
Title2.TextFrame.TextRange.Text = 'image(ceil(64*rand(20,20)))'
As you can see, the code is straight forward and it shouldn't matter if I am doing it in Matlab or any other program.
Instead of making blank slides, I was hoping I could use a specific .POT file as the base of the slides and go from there.
I would eventually need to place text and images at very precise locations---so hopefully this can even be done with PowerPoint activex.
I already have a VBA Macro that does a lot of what I need, but it bases all its work on a premade *.PPTM file. So with activex, I am hoping it will do everything my Macro does, along with create the PowerPoint based on a theme/.POT file, and replace certain text within the template.
Below is the Marco code--- it will be my general guideline for writing the activex. What this code doesn't include is replacing placeholder texts (I currently do that manually).
Code:
Sub GetImagesFromDir()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim imageDir As Variant
Dim tempFileName As String
Dim tempFileNum As String
Dim tempStr As String
Dim varFiles() As Variant
Dim lngFileCount As Long
Dim newSlide As Long
Dim newImage As Shape
Dim newTextBox As Shape
With fd
If .Show = -1 Then
For Each SelectedItems In .SelectedItems
newSlide = -1
imageDir = SelectedItems
tempFileName = Dir(imageDir & "\*.*", vbNormal)
Do Until Len(tempFileName) = 0
If (tempFileName <> ".") And (tempFileName <> "..") Then
tempFileNum = Left(tempFileName, 15)
tempFileNum = Right(tempFileNum, 5)
For i = 1 To ActivePresentation.Slides.Count
For j = 1 To ActivePresentation.Slides(i).Shapes.Count
If (ActivePresentation.Slides(i).Shapes(j).HasTextFrame) Then
If (ActivePresentation.Slides(i).Shapes(j).TextFrame.HasText) Then
tempStr = ActivePresentation.Slides(i).Shapes(j).TextFrame.TextRange
tempStr = Right(tempStr, 5)
If (StrComp(tempStr, tempFileNum, vbTextCompare) = 0) Then
'With ActivePresentation.Slides(i).Shapes.AddShape(Type:=msoShapeRectangle, Left:=0, Top:=0, Width:=100, Height:=100)
With ActivePresentation.Slides(i)
.Select
'Set newTextBox = .Shapes().AddTextbox(msoTextOrientationHorizontal, Left:=0, Top:=0, Width:=100, Height:=100)
'newTextBox.TextFrame.TextRange.Text = "Hello"
Set newImage = .Shapes().AddPicture(tempFileName, msoFalse, msoTrue, 0, 0)
newImage.LockAspectRatio = msoTrue
newImage.Height = 440
newImage.Left = (ActivePresentation.PageSetup.SlideWidth - newImage.Width) / 2 + 5
newImage.Top = (ActivePresentation.PageSetup.SlideHeight - newImage.Height) / 2 + 38
newSlide = 1
End With
End If
End If
End If
Next j
Next i
If (newSlide = -1) Then
ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutTitleOnly
With ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.AddTextbox(msoTextOrientationHorizontal, 712, 60, 200, 50)
.TextFrame.TextRange.Text = tempFileNum
With .TextFrame.TextRange.Font
.Size = 8
.Name = "Arial"
End With
End With
With ActivePresentation.Slides(ActivePresentation.Slides.Count)
Set newImage = .Shapes().AddPicture(tempFileName, msoFalse, msoTrue, 0, 0)
newImage.LockAspectRatio = msoTrue
newImage.Height = 440
newImage.Left = (ActivePresentation.PageSetup.SlideWidth - newImage.Width) / 2 + 15
newImage.Top = (ActivePresentation.PageSetup.SlideHeight - newImage.Height) / 2 + 30
newSlide = -1
End With
newSlide = -1
End If
End If
tempFileName = Dir
Loop
Next SelectedItems
End If
End With
End Sub