Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have numerous macros. I have originally added error handling for each one.
I thought maybe I could reduce my code by making a module for the error....but the problem is when it goes to that sub, it loses the Error(Err); Err information ...it only returns a 0 Any ideas on how I can get this to work is it not possible? Using Excel 2000, vba beginner Thanks! ---------------------------------------------------------- Example of a macro in my spreadsheet (Sheet1): Private Sub AboutCommandButton_Click() On Error GoTo addError 'Workbooks.Open "xxxxxx" 'error testing line - remove first apostrophe AboutPDSR.Show Exit Sub addError: Call MyErrorRoutine End Sub --------------------------------------------------------- My Error module: Sub MyErrorRoutine() 'Error routine for whole spreadsheet Dim UserName As String Dim CpuName As String Dim WhatOffice As String Dim MyFullName As String Dim WorkbookName As String UserName = Environ("USERNAME") CpuName = Environ("COMPUTERNAME") WhatOffice = Environ("USERDOMAIN") MyFullName = ThisWorkbook.FullName WorkbookName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) Open "P:\PDSR\PDSRlogs\ErrorLog-" & WorkbookName & ".log" For Append As #2 'Open ThisWorkbook.Path & "\ErrorLog.log" For Append As #2 'Open file Print #2, Application.Text(Now(), "mm/dd/yyyy HH:mm") _ , UserName, CpuName, WhatOffice, MyFullName _ ; Error(Err); Err 'Write data Close #2 'Close MsgBox "An error has occurred, contact John Doe (extension 123)" End Sub ------------------------------------------------------- The log file report example: 07/17/2007 08:06 doe DMPT04 BNT01 T:\PDSR_Project\PDSR.xls 0 -------------------------------------------------------- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error Handling question | Excel Programming | |||
Error handling question | Excel Programming | |||
Error handling question | Excel Programming | |||
Look up error handling question. | Excel Programming | |||
question error handling | Excel Programming |