Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel VBA code executing a variable as a Sub.

I have a If ....Else ....Then with code:

ElseIf szSelectedReport = "204" Then
RunReport204
ElseIf szSelectedReport = "205" Then
RunReport205
ElseIf szSelectedReport = "220" Then
RunReport220

This goes on for sometime and what I want to produce is a shortened
version i.e.

Dim szReport As String
szReport = CDbl(szSelectedReport)
szReport = "RunReport" & szReport
szReport

So the Sub is called RunReport222 and I have created that but I dont
know how to tell VB to now run that Sub.

Can anyone help me please.

Regards

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel VBA code executing a variable as a Sub.

John,

If you haven't tried this, it might be worth a shot.
After you've set the value of szSelectedReport, pass it to
RunReport222, but allow RunReport222 to have one
argument. (Check out the Excel VB help screen on "Sub
Statement" and the example of using arguments with subs.)
Also check out the "Call Statement" help screen. You
could pass the report number to RunReport222 with:

Call RunReport222(204)

Control would pass to RunReport222, then when it's
finished, control would come back to your original macro.
Hope this helps.
-----Original Message-----
I have a If ....Else ....Then with code:

ElseIf szSelectedReport = "204" Then
RunReport204
ElseIf szSelectedReport = "205" Then
RunReport205
ElseIf szSelectedReport = "220" Then
RunReport220

This goes on for sometime and what I want to produce is a

shortened
version i.e.

Dim szReport As String
szReport = CDbl(szSelectedReport)
szReport = "RunReport" & szReport
szReport

So the Sub is called RunReport222 and I have created that

but I dont
know how to tell VB to now run that Sub.

Can anyone help me please.

Regards

John
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel VBA code executing a variable as a Sub.

Dim szReport As String
szReport = CLng(szSelectedReport)
szReport = "RunReport" & szReport
Application.Run szReport

--
Regards,
Tom Ogilvy


"John Dempsey" wrote in message
om...
I have a If ....Else ....Then with code:

ElseIf szSelectedReport = "204" Then
RunReport204
ElseIf szSelectedReport = "205" Then
RunReport205
ElseIf szSelectedReport = "220" Then
RunReport220

This goes on for sometime and what I want to produce is a shortened
version i.e.

Dim szReport As String
szReport = CDbl(szSelectedReport)
szReport = "RunReport" & szReport
szReport

So the Sub is called RunReport222 and I have created that but I dont
know how to tell VB to now run that Sub.

Can anyone help me please.

Regards

John



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel VBA code executing a variable as a Sub.

Thanks for your response guys. The application.Run philosophy works
but then says it cant find the macro, it exists as a sub under the
code on a form that exists. Is there any way I can tell it to look
there. Or do I have to create the macro RunReport222 and then call
that.

Thanks in advance

John

"Tom Ogilvy" wrote in message ...
Dim szReport As String
szReport = CLng(szSelectedReport)
szReport = "RunReport" & szReport
Application.Run szReport

--
Regards,
Tom Ogilvy


"John Dempsey" wrote in message
om...
I have a If ....Else ....Then with code:

ElseIf szSelectedReport = "204" Then
RunReport204
ElseIf szSelectedReport = "205" Then
RunReport205
ElseIf szSelectedReport = "220" Then
RunReport220

This goes on for sometime and what I want to produce is a shortened
version i.e.

Dim szReport As String
szReport = CDbl(szSelectedReport)
szReport = "RunReport" & szReport
szReport

So the Sub is called RunReport222 and I have created that but I dont
know how to tell VB to now run that Sub.

Can anyone help me please.

Regards

John

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
QUERY & HELP: so slow executing VBA code... :S John Keith Excel Worksheet Functions 3 February 13th 06 03:47 PM
code sample for executing a VB function in Excel using perl newOLE Excel Worksheet Functions 7 August 10th 05 10:26 PM
Problems executing Excel VBA code in Microsoft Office 2003 Umesh Excel Programming 3 July 24th 03 12:45 AM
executing macros with variable names Claude Excel Programming 1 July 17th 03 05:19 PM
executing code when a module opens max Excel Programming 0 July 8th 03 07:37 PM


All times are GMT +1. The time now is 04:30 AM.

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"