|
-
Jul 1st, 2005, 03:08 PM
#1
Thread Starter
New Member
implements interfaces in VBA
Hi,
I am using MS Excel and Im trying to write a macro(VBA) that would use classes and implement an interface. I have no idea what im doing wrong but i keeping getting an error prompting me that the Object module needs to implement a function that the interface has declared. But strangely the function is already implemented. My code is a follows:
clsInterface
VB Code:
Public Property Get LibraryItem_CheckedOut() As Boolean
End Property
clsDerived
VB Code:
Implements clsInterface
Public Sub Class_Initialize()
MsgBox "in derived"
End Sub
Public Property Get LibraryItem_CheckedOut() As Boolean
MsgBox "in derived"
End Property
And finally, ThisWorkbook
VB Code:
Dim cls As clsInterface
Dim derived As clsDerived
Set cls = New clsInterface
Set derived = new clsDerived
Set cls = derived
Ive wrecked my brains of this for hours and have not figured out why i get the error. Again, the error is: "Object module needs to implement 'LibraryItem_CheckedOut' for interface clsInterface
Thanks a million
raven
-
Jul 1st, 2005, 08:32 PM
#2
Frenzied Member
Re: implements interfaces in VBA
I might be wrong, but it looks like you're trying to use .Net code in VBA. I've never heard of Implements & Interfaces in VBA. .Net, Java, yes. Maybe the latest VBA supports that stuff?
Tengo mas preguntas que contestas
-
Jul 1st, 2005, 08:49 PM
#3
Re: implements interfaces in VBA
Implements is VB6 & VBA and in .NET its there but in a different form, its in the Framework. 
Just like when you write an Add-In for Outlook or other Office app. It will use the Implements IDTExtensibility2 interface. This is the
same thing excep raven000 has written a custom class to implement.
Ps, Welcome to the Forums, Raven000.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 11th, 2015, 03:49 PM
#4
New Member
Re: implements interfaces in VBA
This question is a couple months away from being 10 years old but it's still unanswered and shows up in Google search results so I wanted to answer it. The properties/functions/subs defined in the interface need to be prefixed by the interface name and an underscore. Also, it can be initialized in an easier way than initially posted. Changes below.
You can set up properties/functions/subs in the constructor(derived) class without prefixing them or putting them in the interface but they can't be called from outside the class (even if they are public) and are not visible in intellisense. When they are in the interface and the class (as public) they can be called from outside the class and are visible.
clsInterface
VB Code:
Public Property Get LibraryItem_CheckedOut() As Boolean
End Property
clsDerived
VB Code:
Implements clsInterface
Public Sub Class_Initialize()
MsgBox "in derived"
End Sub
Public Property Get clsInterface_LibraryItem_CheckedOut() As Boolean
MsgBox "in derived"
End Property
ThisWorkbook
VB Code:
Dim cls As clsInterface
Set cls = New clsDerived
Sorry for bringing up such an old post but I've stumbled onto it multiple times in the last couple of years.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|