Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Determine if Sub Exists

Is there a way to determine if a sub exists? I have code in an add-in that
calls a sub in the active workbook per the example below. How do I determine
if that sub exists in the activeworkbook or not, to avoid an error?

WBName = ActiveWorkbook.Name
Application.Run "'" & WBName & "'!RemoveSN"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Determine if Sub Exists

Just add an error handler:

Sub test()

On Error GoTo ERROROUT

Application.Run "xxx"

Exit Sub

ERROROUT:
MsgBox Err.Description 'or do whatever is suitable

End Sub


RBS


"Paige" wrote in message
...
Is there a way to determine if a sub exists? I have code in an add-in
that
calls a sub in the active workbook per the example below. How do I
determine
if that sub exists in the activeworkbook or not, to avoid an error?

WBName = ActiveWorkbook.Name
Application.Run "'" & WBName & "'!RemoveSN"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Determine if Sub Exists

Hi,
Try the following:

If ProcExists("RemoveSN") Then Application.Run "'" & WBName & "'!RemoveSN"

Function ProcExists(ProcName As String) As Boolean
Dim i
On Error Resume Next
MsgBox
ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModu le.ProcBodyLine(ProcName,
vbext_pk_Proc)

If Err.Number < 0 Then
ProcExists = False
Else
ProcExists = True
End If
End Function
--
A. Ch. Eirinberg


"Paige" wrote:

Is there a way to determine if a sub exists? I have code in an add-in that
calls a sub in the active workbook per the example below. How do I determine
if that sub exists in the activeworkbook or not, to avoid an error?

WBName = ActiveWorkbook.Name
Application.Run "'" & WBName & "'!RemoveSN"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Determine if Sub Exists

Actually there is no use for a MsgBox instead use the i variable as follows:

If ProcExists("RemoveSN") Then Application.Run "'" & WBName & "'!RemoveSN"

Function ProcExists(ProcName As String) As Boolean
Dim i
On Error Resume Next
i =
ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModu le.ProcBodyLine(ProcName,
vbext_pk_Proc)

If Err.Number < 0 Then
ProcExists = False
Else
ProcExists = True
End If
End Function

--
A. Ch. Eirinberg


"Paige" wrote:

Is there a way to determine if a sub exists? I have code in an add-in that
calls a sub in the active workbook per the example below. How do I determine
if that sub exists in the activeworkbook or not, to avoid an error?

WBName = ActiveWorkbook.Name
Application.Run "'" & WBName & "'!RemoveSN"

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Determine if Sub Exists

Thanks, RB and Howard, for both great ideas!

"Howard31" wrote:

Actually there is no use for a MsgBox instead use the i variable as follows:

If ProcExists("RemoveSN") Then Application.Run "'" & WBName & "'!RemoveSN"

Function ProcExists(ProcName As String) As Boolean
Dim i
On Error Resume Next
i =
ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModu le.ProcBodyLine(ProcName,
vbext_pk_Proc)

If Err.Number < 0 Then
ProcExists = False
Else
ProcExists = True
End If
End Function

--
A. Ch. Eirinberg


"Paige" wrote:

Is there a way to determine if a sub exists? I have code in an add-in that
calls a sub in the active workbook per the example below. How do I determine
if that sub exists in the activeworkbook or not, to avoid an error?

WBName = ActiveWorkbook.Name
Application.Run "'" & WBName & "'!RemoveSN"

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
VBA:: determine if UDF exists? George[_3_] Excel Discussion (Misc queries) 1 May 7th 07 12:57 PM
Determine if a File Exists Connie Excel Programming 1 November 8th 06 09:11 AM
determine if value exists geebee Excel Programming 2 September 19th 06 11:03 PM
Determine if folder exists Terry K Excel Programming 1 June 9th 06 06:26 PM


All times are GMT +1. The time now is 07:47 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"