PC Review


Reply
Thread Tools Rate Thread

CallByName() doesn't

 
 
christopher.allen
Guest
Posts: n/a
 
      12th Sep 2007
CallByName() doesn't seem to be calling for me. I have no compile
errors, the method I'm trying to call is really there in the
CodeModule, but it doesn't execute when called by name.

This code snippet loops through all the components in the workbook.
For any StdModules, it looks for the Proc "savethisModule", and calls
it by name. The MsgBoxes show me that Module2 has a "savethisModule"
method and it's about to be called ... but it doesn't get called.

Note that the hardcoded call at the beginning of this snippet
(commented-out) does work.

So I suspect I'm missing something here ... any ideas?

-Christopher

Public Sub saveAllModules()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim procline As Long

' Call Module2.savethisModule

Set VBProj = ActiveWorkbook.VBProject
For Each VBComp In VBProj.VBComponents
MsgBox "VBComp.Type=" & VBComp.Type & ", Name=" & VBComp.Name
If (VBComp.Type = vbext_ct_StdModule) Then
Set CodeMod = VBComp.CodeModule
procline = 0
On Error Resume Next
procline = CodeMod.ProcBodyLine("savethisModule",
vbext_pk_Proc)
If procline > 0 Then
MsgBox "calling " & "savethisModule" & _
"() in module" & VBComp.Name
Call CallByName(CodeMod, "savethisModule", VbMethod)
End If
End If
Next VBComp
End Sub
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      12th Sep 2007
I don't think a sub routine in a code module can be considered a method of
an object. I would think if you used a class module and instantiated it
this approach would work. If you want to run a sub 'by name' how about" Run
"SubName"?

--
Jim
"christopher.allen" <"at workscape.com"> wrote in message
news:(E-Mail Removed)...
| CallByName() doesn't seem to be calling for me. I have no compile
| errors, the method I'm trying to call is really there in the
| CodeModule, but it doesn't execute when called by name.
|
| This code snippet loops through all the components in the workbook.
| For any StdModules, it looks for the Proc "savethisModule", and calls
| it by name. The MsgBoxes show me that Module2 has a "savethisModule"
| method and it's about to be called ... but it doesn't get called.
|
| Note that the hardcoded call at the beginning of this snippet
| (commented-out) does work.
|
| So I suspect I'm missing something here ... any ideas?
|
| -Christopher
|
| Public Sub saveAllModules()
| Dim VBProj As VBIDE.VBProject
| Dim VBComp As VBIDE.VBComponent
| Dim CodeMod As VBIDE.CodeModule
| Dim procline As Long
|
| ' Call Module2.savethisModule
|
| Set VBProj = ActiveWorkbook.VBProject
| For Each VBComp In VBProj.VBComponents
| MsgBox "VBComp.Type=" & VBComp.Type & ", Name=" & VBComp.Name
| If (VBComp.Type = vbext_ct_StdModule) Then
| Set CodeMod = VBComp.CodeModule
| procline = 0
| On Error Resume Next
| procline = CodeMod.ProcBodyLine("savethisModule",
| vbext_pk_Proc)
| If procline > 0 Then
| MsgBox "calling " & "savethisModule" & _
| "() in module" & VBComp.Name
| Call CallByName(CodeMod, "savethisModule", VbMethod)
| End If
| End If
| Next VBComp
| End Sub


 
Reply With Quote
 
christopher.allen
Guest
Posts: n/a
 
      13th Sep 2007
The Application.Run thing worked, thanks!

Jim Rech wrote:
> I don't think a sub routine in a code module can be considered a method of
> an object. I would think if you used a class module and instantiated it
> this approach would work. If you want to run a sub 'by name' how about" Run
> "SubName"?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of CallByName() George B Microsoft Excel Programming 8 23rd Aug 2008 10:07 PM
Example for VBA function - CallByname! =?Utf-8?B?SGFIYQ==?= Microsoft Excel Misc 0 11th Nov 2006 05:04 PM
Using CallByName with asp.net Olivier Microsoft ASP .NET 2 11th Mar 2004 05:28 PM
CallbyName in C# MFRASER Microsoft C# .NET 2 24th Jan 2004 05:58 PM
CallByName in C#???? Jelle van Baardewijk Microsoft C# .NET 12 20th Jan 2004 02:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 PM.