Results 1 to 10 of 10

Thread: [RESOLVED] VBA Code not working in VB6

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    46

    Resolved [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.
    Last edited by Beall49; Dec 18th, 2008 at 12:15 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    46

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    46

    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
    Last edited by Beall49; Dec 18th, 2008 at 01:17 PM.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    46

    Re: VBA Code not working in VB6

    ^ You are a god, it worked the first time.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA Code not working in VB6

    Cool, glad its working now.

    Did you notice the changes and why?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    46

    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...

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width