PowerPoint VBA type mismatch error with FillFormat object

In the code below, I pass the FillFormat object of a selected shape to the function. I then pass the FillFormat object for the text within the selected shape but it raises a Type Mismatch error. The FillFormat object TypeName is the same in both cases and it only appears as a member of the PowerPoint library and is not duplicated in the Office library. I know I can declare oFF As Object but I'd prefer to understand why am I getting this mismatch error in the first place? To test, you just need to select a shape with some text in it on a slide and then run the Test procedure.

Sub Test()
  ' Format the fill for the selected shape
  Debug.Print TypeName(ActiveWindow.Selection.ShapeRange(1).Fill)
  ChangeFillFormat ActiveWindow.Selection.ShapeRange(1).Fill
  
  ' Format the fill for the text inside the selected shape
  Debug.Print TypeName(ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Font.Fill)
  ChangeFillFormat ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Font.Fill
End Sub

Function ChangeFillFormat(oFF As FillFormat)
  ' Do stuff with the fill format
End Function

Open in new window

LVL 14
Jamie GarrochPowerPoint Consultant & DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
I think I am getting close to the answer. Having looked at the objects in the hierarchy of each reference for the Shape and Font and the corresponding classes in the object browser, it appears that because VBA excludes references to libraries that there is a mix of two in use.

FillFormat for Shape.Fill = PowerPoint
FillFormat for Font2.Fill = Office

Is my assumption correct?

Office library references
What I don't understand is how FillFormat can be used in two different libraries but only declared in one (in this case as a PowerPoint member) and hence how to avoid this kind of type mismatch error in the future.
0
Jamie GarrochPowerPoint Consultant & DeveloperAuthor Commented:
As eluded to above, it seems the mismatch is due to the way methods and properties cascade down the object model hierarchy across multiple libraries, although it's not possible to see this when coding and using IntelliSense (you have to look at the Object Browser). The solution I used in the end was to incorporate a custom conditional compiler constant as follows:

#Const EARLY_BINDING = False ' True in dev mode for IntelliSense, False in test/production

Sub Test()
  ' Format the fill for the selected shape
  ChangeFillFormat ActiveWindow.Selection.ShapeRange(1).Fill
  
  ' Format the fill for the text inside the selected shape
  ChangeFillFormat ActiveWindow.Selection.ShapeRange(1).TextFrame2.TextRange.Font.Fill
End Sub

#If EARLY_BINDING Then
Function ChangeFillFormat(oFF As FillFormat)
#Else
Function ChangeFillFormat(oFF As Object)
#End IF
  ' Do stuff with the fill format
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.