0

I had assigned object names to objects in a 2007 Powerpoint file for automation purposes. I ran the automated code in another machine which has office 2003 and found that the object names are dynamically changing there hence the automated code throws an error.

I tried renaming the objects again in that machine using VBA and it works while debugging. But the error throws up when I rerun the automation code.

Is it a compatibility issue between the 2 versions or something else?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • A thought as to why shape names might change: PPT 2003 can't open the PPTX files from 2007 unless you've installed (what I think was called) the compatibility kit, which does an on-the-fly conversion from PPTX to PPT formats. It's probably creating all new shapes/objects and may not be preserving the original shape names when it does so. – Steve Rindsberg Apr 16 '21 at 19:39

2 Answers2

1

that was my problem with differentversions of Word. Generally, Code to the highest version of PowerPoint might not be supported under earlier versions. but sometimes the code works but the method which it refereed may be caused the problem.

I recommend use late binding (... As Object) to solve the problem

revision with an example:

The difference is that you bind the object library in code at run-time. You don't use Tools-References. something like that:

Sub ppt()

    Dim olApp As Object

    Set olApp = CreateObject("PowerPoint.Application")

End Sub
David Peterson
  • 552
  • 14
  • 31
  • Could you help me with the late binding concept you mentioned? Some reference to it would be helpful. Also will the method ensure that the code works? – Vishal Kapoor May 13 '12 at 11:10
  • I've edited my answer, remember that the difference is the creation of object( CreateObject("PowerPoint.Application") ) – David Peterson May 14 '12 at 06:42
0

By "object names", do you mean shape names? Ie the shape's .Name property? This does seem to be buggy.

Consider using tags on the shapes you need to work with. For example, assuming a reference to your shape in oSh, instead of using oSh.Name = "Remember me", do something like:

oSh.Tags.Add "ShapeName","RememberMe"

Then when you need to get a reference to a shape, use a function like:

Function ShapeNamed(oSl as Object, sName as string) as Shape
  Dim oSh as Shape
  For Each oSh in oSl.Shapes
    If oSh.Tags("ShapeName") = sName Then
      Set ShapeNamed = oSh
      Exit Function
    End If
  Next
End Function

oSl is declared as Object rather than Slide so you can pass the function Slides, Masters, Layouts, etc.

Steve Rindsberg
  • 3,470
  • 1
  • 16
  • 10