Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2005, 06:56 PM
Authorized User
 
Join Date: Jun 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default NewEnum Function

Hi--

 VB 6 allows the creation in a class module of a NewEnum function (see below). The function permits the class to be searched using a For Each loop.

When I try to do the same in Excel Vba I get the message:

 Compile error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic

Is this a limitation of Excel Vba or is there a way to set up the references and/or properties to get this functionality

Thanks,

Barry
--------------------------------------------
Public Function NewEnum() As IUnknown
  Set NewEnum = myFieldKey.[_NewEnum]
End Function


 
Old February 8th, 2005, 05:25 AM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in VB6, to specify this attribute for the NewEnum method you use the "Procedure Attributes" menu item. In VBA there's no similar option, however you can achieve the same result by either:

1) create the collection class (I assume that's what it is) in VB6, then take the resulting ".cls" file and import into your VBA project.

2) from VBA, export the class module and open it in a text editor such as notepad. Modify the function so that it reads:

Code:
Public Function NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
  Set NewEnum = myFieldKey.[_NewEnum]
End Function
then save the ".cls" file, and import it back into your VBA project.

As you can see, both are hacks, but they're accepted ways around the problem





Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
Please help with function fugru Excel VBA 2 January 29th, 2007 04:34 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.