|
Visual Basic (VB and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Please read the DISCLAIMER.
Here is an INDEX to all the procedures.
You will probably need one copy of my GLOBAL DECLARATIONS.
Public Function boolProcedureExists(strProc As String, Optional strTemplate As String = "Normal.dot") As Boolean
' Procedure : boolProcedureExists
' Description: determine if a nominated procedure exists
' Copyright: Chris Greaves Inc.
' Inputs: A STRING procedure name, optional template name.
' Returns: TRUE if the procedure can be found in the template
' Assumes: Nothing
' Side Effects: None.
' Tested: By the calls shown below.
' NOTE: this version has been stripped-down to serach ONLY the Normaltemplate.
' Set the default result
boolProcedureExists = False
' We will be activating another document, so remember the current document.
Dim strDoc As String
strDoc = ActiveDocument.Name
' If the template document is already open, we should leave it open when we are done.
Dim boolClose As Boolean
If boolDocIsOpen(strTemplate) Then
boolClose = False
Else
boolClose = True
End If
' Now attempt to open the template document and search for the procedure.
If boolTestLockedTemplate(NormalTemplate) Then
Call ERL("0003", intcErrorSevere, "I'm sorry, your Normal template is locked and i cannot run the procedure")
Else
'For each module in the supplied template
Dim oItem As Object
For Each oItem In NormalTemplate.VBProject.VBComponents
Dim lngProc As Long
On Error Resume Next
lngProc = oItem.CodeModule.ProcCountLines(strProc, vbext_pk_Proc)
If lngProc > 0 Then ' Some lines exists for this procedure!
boolProcedureExists = True
Exit For
Else
End If
Next oItem
End If
If boolClose Then
' DocClose (strTemplate)
Else
End If
' We have activated another document, so reactivate the original document.
Documents(strDoc).Activate
'Sub TESTboolProcedureExists()
' MsgBox boolProcedureExists("process")
' MsgBox boolProcedureExists("process", "normal.dot")
' MsgBox boolProcedureExists("?_^&$016", "normal.dot")
' MsgBox boolProcedureExists("process", "under016.dot")
' MsgBox boolProcedureExists("process", "files017.dot")
' MsgBox boolProcedureExists("process", "?_^&$016.dot")
'End Sub
End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Thursday, November 15, 2001 |