Hi, I am trying to copy some photos from a folder, into a new PowerPoint presentation 2007, using Access 2007 VBA.
I have two problems:
1- I must open manually a new PowerPoint presentation, before running the Access VBA, otherwise I get the error message:
“-2147188160 Shape (unknown member):Invalid request. To select a shape, its view must be active”
2- When I open a new PowerPoint manually, then I run the Access VBA, It copies the first picture into the first slide, then the second picture into the second slide, then I get the SAME error message as mentioned above.
BUT:
If I run the Access VBA step by step, and I manually select the next slide after the statement:
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
it works fine, without any error.
Here is the entire code:
Sub cmdPowerPoint_Click()
Dim db As Database
Dim rs As Recordset
Dim ppObj As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim FilePathAndName As String
Dim I As Integer
On Error GoTo err_cmdOLEPowerPoint
' Open up a recordset on the Employees table.
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
' Open up an instance of Powerpoint.
Set ppObj = New PowerPoint.Application
Set ppPres = ppObj.Presentations.Add
' Setup the set of slides and populate them with data from the
' set of records.
I = 1
With ppPres
While Not rs.EOF
FilePathAndName = "C:\Photos\PhotosAll\Slide" & Trim(Str(I)) & ".jpg"
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
.Shapes.AddPicture( _
FileName:=FilePathAndName, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
Width:=720, Height:=540).Select
.SlideShowTransition.EntryEffect = ppEffectFade
With .Shapes(2).TextFrame.TextRange
.Text = CStr(rs.Fields("LastName").Value)
.Characters.Font.Color.RGB = RGB(255, 0, 255)
.Characters.Font.Shadow = True
End With
.Shapes(1).TextFrame.TextRange.Characters.Font.Size = 50
I = I + 1
End With
rs.MoveNext
Wend
End With
' Run the show.
ppPres.SlideShowSettings.Run
Exit Sub
err_cmdOLEPowerPoint:
MsgBox Err.Number & " " & Err.Description
End Sub
So I have two questions:
1- What statement should I add, to avoid having to open a new PowerPoint document manually?
2- What statement should I add so that the selection goes automatically to the next slide, after the statement:
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
Thank you in advance.
I have two problems:
1- I must open manually a new PowerPoint presentation, before running the Access VBA, otherwise I get the error message:
“-2147188160 Shape (unknown member):Invalid request. To select a shape, its view must be active”
2- When I open a new PowerPoint manually, then I run the Access VBA, It copies the first picture into the first slide, then the second picture into the second slide, then I get the SAME error message as mentioned above.
BUT:
If I run the Access VBA step by step, and I manually select the next slide after the statement:
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
it works fine, without any error.
Here is the entire code:
Sub cmdPowerPoint_Click()
Dim db As Database
Dim rs As Recordset
Dim ppObj As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim FilePathAndName As String
Dim I As Integer
On Error GoTo err_cmdOLEPowerPoint
' Open up a recordset on the Employees table.
Set db = CurrentDb
Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
' Open up an instance of Powerpoint.
Set ppObj = New PowerPoint.Application
Set ppPres = ppObj.Presentations.Add
' Setup the set of slides and populate them with data from the
' set of records.
I = 1
With ppPres
While Not rs.EOF
FilePathAndName = "C:\Photos\PhotosAll\Slide" & Trim(Str(I)) & ".jpg"
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
.Shapes.AddPicture( _
FileName:=FilePathAndName, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
Width:=720, Height:=540).Select
.SlideShowTransition.EntryEffect = ppEffectFade
With .Shapes(2).TextFrame.TextRange
.Text = CStr(rs.Fields("LastName").Value)
.Characters.Font.Color.RGB = RGB(255, 0, 255)
.Characters.Font.Shadow = True
End With
.Shapes(1).TextFrame.TextRange.Characters.Font.Size = 50
I = I + 1
End With
rs.MoveNext
Wend
End With
' Run the show.
ppPres.SlideShowSettings.Run
Exit Sub
err_cmdOLEPowerPoint:
MsgBox Err.Number & " " & Err.Description
End Sub
So I have two questions:
1- What statement should I add, to avoid having to open a new PowerPoint document manually?
2- What statement should I add so that the selection goes automatically to the next slide, after the statement:
With .Slides.Add(rs.AbsolutePosition + 1, ppLayoutTitle)
Thank you in advance.