Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 7th, 2005, 06:56 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old February 8th, 2005, 05:25 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.