VBA powerpoint problems

S

simon cory

Hello Experts,

I have an application that contains the Microsoft VBA Integrated Development
Environment (IDE) to allow for scripting.

With the initial pointers from people here, I've been trying to learn and
write a little script in VBA that takes "viewpoints" from my application and
automatically adds them to PowerPoint.

Here is my code with as much explanation as possible:

Private Sub CommandButton1_Click()
Dim vCount As Integer 'number of viewpoints
Dim vp As Viewpoint 'viewpoint
Dim PPApp As Object 'PowerPoint.Application
Dim PPPres As Object 'PowerPoint.Presentation
Dim PPSlide As Object 'PowerPoint.Slide
Dim PPShp As Object 'PowerPoint.Shape
Dim vi As V3DView '3D view of molecule

vCount = ThisModel.Viewpoints.Count 'counts number of viewpoints

'create powerpoint session
Set PPApp = CreateObject("Powerpoint.Application")
Set PPPres = PPApp.Presentations.Add
PPApp.Visible = True
'cycle through all viewpoints and add slides and captions
For i = 1 To vCount
'select new viewpoint, update changes, and copy to clipboard
Call ThisModel.Viewpoints(i).Apply(ThisModel.ActiveView.V3DView)
ThisModel.UpdateChanges
Set vp = ThisModel.Viewpoints(i)
Set vi = ThisModel.ActiveView.V3DView
Call vi.Copy

Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
Set PPShp = PPSlide.Shapes.Paste(1)
If Not PPShp Is Nothing Then
Call CenterShape(PPShp, PPPres)
Else
MsgBox "Failure to paste shape.", vbCritical, _
"PowerPoint Automation Example"
End If
'With .Shapes.AddTextbox(1, 0, 0, _
'PPPres.PageSetup.SlideWidth, _
'PPPres.PageSetup.SlideHeight)
'.TextFrame.TextRange.Text = "Enter captions here"
'.TextFrame.TextRange.ParagraphFormat.Alignment = 2
' Postion caption shape as desired
'
'

Next
PPPres.NewWindow


End Sub

'-------------------------------

Sub CenterShape(oShp As Object, oPres As Object)
With oShp
.Left = (PPPres.PageSetup.SlideWidth - .Width) / 2
.Top = (PPPres.PageSetup.SlideHeight - .Height) / 2
End With
End Sub
'-----------------

When I run the script, it opens PowerPoint, adds the first "viewpoint"
image, but the says there is an error with the following line:

.Left = (PPPres.PageSetup.SlideWidth - .Width) / 2

run time rror '424' object required.

Ideally, I would like a new slide for each of the (variable number of)
viewpoints, but I know I'm setting this up wrong.

Just started VBA and powerpoint this week so your suggestions would be
greatly appreciated..thanks in advance.

SC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top