Question : Error on Running Powerpoint from Access

This code, written for Office XP as an Access module, gets a "Type Mismatch" error where indicated.  

Any help with this would be appreciated.

Thanks!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
Global objPPT As PowerPoint.Application
Global objPRES As PowerPoint.Presentation
 
Sub GetPPT()
 
On Error GoTo CreatePPT
Set objPPT = GetObject(, "PowerPoint.Application")
Exit Sub
CreatePPT:
Set objPPT = CreateObject("PowerPoint.Application")
Exit Sub
 
End Sub
 
Sub Test2342342()
 
    GetPPT
    Dim aPres As PowerPoint.Presentation
    objPPT.Presentations.Add
    Dim aP As PowerPoint.Presentation
    
    Set aP = objPPT.Presentations(1)
    aP.Slides.Add 1, ppLayoutBlank
    Dim sld1 As Slide
    Set sld1 = aP.Slides(1)
           
    With aP.SlideShowSettings
        .ShowType = ppShowTypeSpeaker
        .LoopUntilStopped = msoFalse
        .ShowWithNarration = msoTrue
        .ShowWithAnimation = msoTrue
        .RangeType = ppShowAll
        .AdvanceMode = ppSlideShowUseSlideTimings
        .PointerColor.RGB = RGB(Red:=255, Green:=0, Blue:=0)
        .Run
    End With
    
    Dim SSW As SlideShowWindow
    Set SSW = aP.SlideShowWindow
    Dim slds As Slides
    Set slds = aP.Slides
    
    Dim mS As Slide
    Set mS = slds(1)
        
    mS.Shapes.AddShape msoShape8pointStar, 200, 200, 30, 30
    
    Dim sh As Shape
    Dim shs As Shapes
    
    Set shs = mS.Shapes  ' <<<< Error Here = "TYPE MISMATCH"
    Set sh = shs(1)
    
    With mS.Shapes(1)
        For n = 1 To 100
        sh.Left = sh.Left + Cos(n / pi) * 100
        sh.Top = sh.Top + Cos(n / pi) * 100
        DoTimer (0.033)
        Next n
    End With
    
End Sub

Answer : Error on Running Powerpoint from Access

codequest,
  Lots of libraries define a Shape object and a Shapes object. You are getting the mismatch because you have a reference to a library like Word, Excel, or Publisher that defines Shape higher in your list of references.

Dim sh as Shape ' equates to Dim sh as Word.Shape or Excel.Shape, etc.

One fix is to move the Powerpoint reference higher in the list. But that may break other code. The real fix is to specify the library:

Dim sh as Powerpoint.Shape
Dim shs as Powerpoint.Shapes

Then, reference order doesn't matter.

HTH,

pT72
Random Solutions  
 
programming4us programming4us