回想すると、答えは私には明らかです。
中央エラーハンドラは、エラーの原因となったモジュールをどのように知っていますか?プライベートモジュール名文字列を中央エラーハンドラに渡します。
同様に、私は中央エラーハンドラの別のパラメータとしてブックの配列を渡すことができます!
ので、代わりにこのように見える中央のエラーハンドラ:振り返ってみると
Public Function bCentralErrorHandler(_
ByVal sModule As String, _
ByVal sProc As String, _
Optional ByVal wbChildWorkbooks() As Workbook, _
Optional ByVal sFile As String, _
Optional ByVal bEntryPoint As Boolean) As Boolean
かなり明白:
Public Function bCentralErrorHandler(_
ByVal sModule As String, _
ByVal sProc As String, _
Optional ByVal sFile As String, _
Optional ByVal bEntryPoint 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 Then sErrMsg = Err.Description
' 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 application 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 = " " & Application.UserName & sFullSource & ", Error " & _
CStr(lErrNum) & ": " & sErrMsg
' 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
Application.ScreenUpdating = True
MsgBox sErrMsg, vbCritical, gsAPP_NAME
' 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
は、私は定義を変更します。無駄な質問を申し訳ありません。
私はあなたにはいません:変数 'X'がVBAプロジェクトの任意のモジュールで' Public'として宣言されている場合、そのプロジェクトのすべてのモジュール間で共有されるので、 'X'実際に宣言されているモジュール名を前に置くことはありません – user3598756
各モジュールには独自のワークブック配列があります。しかし私は、私が思い出した明白な解決策を思いついたと思います。私は以下に投稿します –