#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default AddressOf

Hello,
Doe's "AddressOf" works with Excel macros?
I keep getting a Compile Error for using it.
"Invalid use of AddressOf operator"

This is the code:

Private Sub TestSub()
i = 0
End Sub

Private Function GetAddr(ByVal Addr As Long) As Long
GetAddr = Addr
End Function

Private Sub Test()
Dim Addr as Long
Addr = GetAddr (AddressOf TestSub)
End Sub

The error is for Test Sub
Tnx


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default AddressOf

I don't have much experience with AddressOf, but from what I can see, if
TestSub is moved to a regular module that should fix it.

From my book "VB and VBA In a Nutshell" by Paul Lomax:

AddressOf Operator
Rules at a Glance:
"The callback function must be stored in a code module; attempting to store
it in a class or form module generates a compile-time error, "Invalid use of
AddressOf operator."

When I tested your code, with TestSub moved to a regular code module, it
worked.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." wrote in message
...
Hello,
Doe's "AddressOf" works with Excel macros?
I keep getting a Compile Error for using it.
"Invalid use of AddressOf operator"

This is the code:

Private Sub TestSub()
i = 0
End Sub

Private Function GetAddr(ByVal Addr As Long) As Long
GetAddr = Addr
End Function

Private Sub Test()
Dim Addr as Long
Addr = GetAddr (AddressOf TestSub)
End Sub

The error is for Test Sub
Tnx




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default AddressOf

Tnx a lot,
What do you mean by "regular code module"?

"Tim Zych" <tzych@nospam at earthlink dot net wrote in message
...
I don't have much experience with AddressOf, but from what I can see, if
TestSub is moved to a regular module that should fix it.

From my book "VB and VBA In a Nutshell" by Paul Lomax:

AddressOf Operator
Rules at a Glance:
"The callback function must be stored in a code module; attempting to
store it in a class or form module generates a compile-time error,
"Invalid use of AddressOf operator."

When I tested your code, with TestSub moved to a regular code module, it
worked.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." wrote in message
...
Hello,
Doe's "AddressOf" works with Excel macros?
I keep getting a Compile Error for using it.
"Invalid use of AddressOf operator"

This is the code:

Private Sub TestSub()
i = 0
End Sub

Private Function GetAddr(ByVal Addr As Long) As Long
GetAddr = Addr
End Function

Private Sub Test()
Dim Addr as Long
Addr = GetAddr (AddressOf TestSub)
End Sub

The error is for Test Sub
Tnx






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default AddressOf

In the VBE - Insert - Module.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." wrote in message
...
Tnx a lot,
What do you mean by "regular code module"?

"Tim Zych" <tzych@nospam at earthlink dot net wrote in message
...
I don't have much experience with AddressOf, but from what I can see, if
TestSub is moved to a regular module that should fix it.

From my book "VB and VBA In a Nutshell" by Paul Lomax:

AddressOf Operator
Rules at a Glance:
"The callback function must be stored in a code module; attempting to
store it in a class or form module generates a compile-time error,
"Invalid use of AddressOf operator."

When I tested your code, with TestSub moved to a regular code module, it
worked.


--
Regards,
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility

"E.Z." wrote in message
...
Hello,
Doe's "AddressOf" works with Excel macros?
I keep getting a Compile Error for using it.
"Invalid use of AddressOf operator"

This is the code:

Private Sub TestSub()
i = 0
End Sub

Private Function GetAddr(ByVal Addr As Long) As Long
GetAddr = Addr
End Function

Private Sub Test()
Dim Addr as Long
Addr = GetAddr (AddressOf TestSub)
End Sub

The error is for Test Sub
Tnx








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default AddressOf

Yup, got it. works.
Tnx again


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AddressOf limitations 2002 vs. 97 John.Greenan Excel Programming 2 September 23rd 06 04:44 PM
AddressOf Nightmare RAFAAJ2000[_2_] Excel Programming 8 June 28th 05 10:42 AM
AddressOf in Excel 2002 VBA? Tom Schelfaut Excel Programming 5 May 4th 05 02:38 PM
usage "AddressOf TimerProc" in Excel97 tom taol Excel Programming 3 January 14th 05 09:57 AM
AddressOf / Windows API question Amos Excel Programming 1 February 25th 04 05:18 PM


All times are GMT +1. The time now is 03:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"