English 中文(简体)
在VBA中,如何从一个没有申请的未定单元中找到一种具体方法?
原标题:In VBA, how to call a specific method from an unkown module without Application.Run()?

我试图在VBA中建立一个类似于博士的 h机制(前面和批评,我知道这种机制是站不住脚的)。 我之所以努力,是因为我没有找到其他途径来适当分清整个团队的工作,因此我希望这一机制能够带来一些Dorupal的受审判和休战的心态。 我这样做了,但我很抱歉。

这里,我做了些什么:一个发送器模块,基本上对我项目的所有单元进行操作,并测试这些模块是否以具体的预设装置开始(指它们重新 h取模块),如果它找到,则:

Call Application.Run(Module.Name & ".hook_" & HookName)

我知道,并非原样,但如果我凌驾于所有模块,并援引所有工作手册活动的空白,那么它就开始像《非洲就业行动计划》那样 little。 这意味着,我允许在不污染本工作手册中的代码的情况下,使用任何模块。 更糟的是,不同的人将在不同的ook模块(BIG BONUS)内处理不同的特征。

正如我说过的那样,这项工作,但我还必须打上<条码>申请。 EnableEvents = False before these insigns, and Application. EnableEvents = real after the insigns, so,我不会最终陷入无限的休战。 这也是ok。

我的问题是: 我只想作一大错误的手法,这样,如果有人ook弄一些东西,我就可以在我的顶端发送器和可以再利用的事件中追索错误。 象一个好的想法一样,但由于我使用<代码>Application.Run(),整个错误处理机制在中间被打破,因此,发送者获得的笔录中出现的任何错误就如此。 这也将留下为<代码>False而设的申请活动,这种活动是坏的(在我援引ook之前,将Im打到<代码>False)。

我的问题是: 是否有办法在未经申请的未定单元内援引具体名称的功能。 顺便说一句,我的错误对发送者来说是多余的? 我试图这样做:

Call Module.hook_WorksheetChange()

但是,它没有汇编成册(我没有听从成功,但我希望......)。 www.un.org/Depts/DGACM/index_french.htm 标有VBComponent和hook_WorksheetChange()的物体是单元中定义的实际<编码>。

想法? 不要让每个人都总是处理<条码>申请,那就太过了。 EnableEvents = Real Cleanup - it should only be concern with it s own, norm-specific misprocess.

最佳回答

如果你以所述方式重新处理你错误,那么你应被罚款。

基本上,Bovey等人规定,每个入境点都例行设有一个分站,每个不入境点都例行行使职能。 所有职能都归还了显示错误状况的细菌。 所有错误都普遍存在。 它运作良好。

这里唯一的问题是申请是否适用。 移动能够回馈价值。 我刚刚检查,可以检查。

我强烈建议该书,但为了完整起见,我将其建议的模板如下。

希望会有所帮助。 Oh,如果你重新在Excel/VBA中做复杂的 st,读到

Entry point routines

Public Sub test()
    Const sSOURCE As String = "test"
    On Error GoTo ErrorHandler

      Your code goes here
    If Not Application.Run("YourModule.YourFunction") Then Err.Raise glHANDLED_ERROR
      all non-entry routines are called with this If ... Then structure

ErrorExit:
    Exit Sub

ErrorHandler:
    If bCentralErrorHandler(m_sModule, sSOURCE, , True) Then
        Stop
        Resume
    Else
        Resume ErrorExit
    End If
End Sub

Non entry point routines

Private Function MyFunction(SomeParameter)

    Const sSOURCE As String = "MyFunction"
    Dim bReturn As Boolean
    bReturn = True
    On Error GoTo ErrorHandler

      your code goes here
    MsgBox("something")

ErrorExit:

    MyFunction = bReturn
    Exit Function

ErrorHandler:

    bReturn = False
    If bCentralErrorHandler(m_sModule, sSOURCE) Then
        Stop
        Resume
    Else
        Resume ErrorExit
    End If

End Function

Central Error-Handling Routine

 
  Description:  This module contains the central error
                handler and related constant declarations.
 
  Authors:      Stephen Bullen, www.oaltd.co.uk
                Rob Bovey, www.appspro.com
 
  Chapter Change Overview
  Ch#   Comment
  --------------------------------------------------------------
  12    Initial version
 
Option Explicit
Option Private Module

  **************************************************************
  Global Constant Declarations Follow
  **************************************************************
Public Const gbDEBUG_MODE As Boolean = False      True enables debug mode, False disables it.
Public Const glHANDLED_ERROR As Long = 9999       Run-time error number for our custom errors.
Public Const glUSER_CANCEL As Long = 18           The error number generated when the user cancels program execution.


  **************************************************************
  Module Constant Declarations Follow
  **************************************************************
Private Const msSILENT_ERROR As String = "UserCancel"     Used by the central error handler to bail out silently on user cancel.
Private Const msFILE_ERROR_LOG As String = "GHQ_Error.log"    The name of the file where error messages will be logged to.


                                                                
  Comments: This is the central error handling procedure for the
            program. It logs and displays any run-time errors
            that occur during program execution.
 
  Arguments:    sModule         The module in which the error occured.
                sProc           The procedure in which the error occured.
                sFile           (Optional) For multiple-workbook
                                projects this is the name of the
                                workbook in which the error occured.
                bEntryPoint     (Optional) True if this call is
                                being made from an entry point
                                procedure. If so, an error message
                                will be displayed to the user.
 
  Returns:      Boolean         True if the program is in debug
                                mode, False if it is not.
 
  Date          Developer       Chap    Action
  --------------------------------------------------------------
  05/28/04      Rob Bovey       Ch12    Initial version
 
Public Function bCentralErrorHandler( _
            ByVal sModule As String, _
            ByVal sProc As String, _
            Optional ByVal sFile As String, _
            Optional ByVal bEntryPoint As Boolean, _
            Optional bShowDesc As Boolean) As Boolean

    Static sErrMsg As String

    Dim iFile As Integer
    Dim lErrNum As Long
    Dim sFullSource As String
    Dim sPath As String
    Dim sLogText As String

      Grab the error info before it s cleared by
      On Error Resume Next below.
    lErrNum = Err.Number
      If this is a user cancel, set the silent error flag
      message. This will cause the error to be ignored.
    If lErrNum = glUSER_CANCEL Then sErrMsg = msSILENT_ERROR
      If this is the originating error, the static error
      message variable will be empty. In that case, store
      the originating error message in the static variable.
    If Len(sErrMsg) = 0 Or bShowDesc Then sErrMsg = Err.description
    If Erl > 0 Then sErrMsg = sErrMsg & " at line " & Erl

      We cannot allow errors in the central error handler.
    On Error Resume Next

      Load the default filename if required.
    If Len(sFile) = 0 Then sFile = ThisWorkbook.name

      Get the gxlapp directory.
    sPath = ThisWorkbook.Path
    If Right$(sPath, 1) <> "" Then sPath = sPath & ""

      Construct the fully-qualified error source name.
    sFullSource = "[" & sFile & "]" & sModule & "." & sProc

      Create the error text to be logged.
    sLogText = "  " & sFullSource & ", Error " & _
                        CStr(lErrNum) & ": " & sErrMsg & IIf(Erl > 0, ". Line: " & Erl, "")

      Open the log file, write out the error information and
      close the log file.
    iFile = FreeFile()
    Open sPath & msFILE_ERROR_LOG For Append As #iFile
    Print #iFile, Format$(Now(), "mm/dd/yy hh:mm:ss"); sLogText
    If bEntryPoint Then Print #iFile,
    Close #iFile

      Do not display or debug silent errors.
    If sErrMsg <> msSILENT_ERROR Then

          Show the error message when we reach the entry point
          procedure or immediately if we are in debug mode.
        If bEntryPoint Or gbDEBUG_MODE Then
            gxlApp.ScreenUpdating = True
            MsgBox sErrMsg
            DoEvents
              Clear the static error message variable once
              we ve reached the entry point so that we re ready
              to handle the next error.
            sErrMsg = vbNullString
        End If

          The return vale is the debug mode status.
        bCentralErrorHandler = gbDEBUG_MODE

    Else
          If this is a silent error, clear the static error
          message variable when we reach the entry point.
        If bEntryPoint Then sErrMsg = vbNullString
        bCentralErrorHandler = False
    End If

End Function
问题回答

暂无回答




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签