[RESOLVED] VBA Code not working in VB6
I was building something to run an update in PPT to refresh the links. I am now having to update some related things in access along with some pivot tables in Excel. So I decided to just build it in VB6. However, my powepoint code does not work, I have added the powerpoint libraries into VB, but it fails everytime. I open the ppt but when it gets to checking the shape.type it fails....any idea?
Code:
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoLinkedOLEObject Then 'Fails Here on oshp.Type
oshp.LinkFormat.Update
End If
Next oshp
Next osld
EDIT:This code is straight out of PPT so the ActivePresentation thing obviously needs to be changed, I accidently deleted the updates I made in vb6
EDIT: The error it gives me is a compile error: Method or data member not found, which sounds like a reference but I cant find anymore references that I should need.
Re: VBA Code not working in VB6
VBA code is not 100% compatible with VB6 and visa versa.
You did add a reference to PowerPoint so msoLinkedOLEObject is defined?
Re: VBA Code not working in VB6
^Yes sir....MS PPT 11.0 Obj Lib
Could I be missing anything else?
This code should work.
Re: VBA Code not working in VB6
.Type isnt necessarily a property of a Shape object.
Check it out in the Object Browser and Intelisense. ;)
Do you have a reference to Office 11.0 too?
Re: VBA Code not working in VB6
Ok so I noticed that I wasn't telling it what object, so I got past that, now though it fails on the first line saying the object doesnt support this property or method.
Code:
Dim oSld As Slide
Dim oShp As Shape
Set objPpt = CreateObject("PowerPoint.Application")
objPpt.Visible = True
Set objPres = objPpt.Presentations.Open("C:\Documents and Settings\u1\Desktop" _
& "\Flash Report.ppt")
For Each oSld In objPpt 'it fails on this line
For Each oShp In oSld.Shapes
If objPpt.Shape.Type = msoLinkedOLEObject Then
objPpt.oShp.LinkFormat.Update
End If
Next oShp
Next oSld
End Sub
Re: VBA Code not working in VB6
Try it like this...
Code:
Option Explicit
Private Sub Form_Load()
Dim oSld As PowerPoint.Slide
Dim oShp As PowerPoint.Shape
Dim objPpt As PowerPoint.Application
Set objPpt = CreateObject("PowerPoint.Application")
objPpt.Visible = True
Set objPres = objPpt.Presentations.Open("C:\Documents and Settings\u173934\Desktop\BSA-AML Production Flash Report.ppt")
For Each oSld In objPpt.Presentations.Item(0).Slides 'it fails on this line
For Each oShp In oSld.Shapes
If oShp.Type = msoLinkedOLEObject Then
oShp.LinkFormat.Update
End If
Next oShp
Next oSld
End Sub
End Sub
Re: VBA Code not working in VB6
^ You are a god, it worked the first time.
Re: VBA Code not working in VB6
Cool, glad its working now. :)
Did you notice the changes and why? ;)
Re: VBA Code not working in VB6
I noticed the changes but I dont think I could explain what its really doing besides possibly finding each slide...
Re: VBA Code not working in VB6
The way you had it before was looping off of the Application object which doesnt have a Slides collection. Then the inner loop was looping off of the oShp object which was invalid because of the previous error.
So the fix was to loop using the first presentation's slides collection. Then you can access each of the shapes inside that slide in your inner loop. ;)