|
1 | | -VERSION 1.0 CLASS |
2 | | -BEGIN |
3 | | - MultiUse = -1 'True |
4 | | -END |
5 | | -Attribute VB_Name = "EventListener" |
6 | | -Attribute VB_GlobalNameSpace = False |
7 | | -Attribute VB_Creatable = False |
8 | | -Attribute VB_PredeclaredId = False |
9 | | -Attribute VB_Exposed = False |
10 | | -Option Explicit |
11 | | - |
12 | | -'This class receives and acts upon events from the excel application. |
13 | | -' To disable this eventhandling, simply don't instantiate this class. See Thisworkbook. |
14 | | - |
15 | | - |
16 | | -Private WithEvents App As Application |
17 | | -Attribute App.VB_VarHelpID = -1 |
18 | | - |
19 | | - |
20 | | -Private Sub Class_Initialize() |
21 | | - Set App = Application |
22 | | -End Sub |
23 | | - |
24 | | - |
25 | | -Private Sub App_WorkbookAfterSave(ByVal wb As Workbook, ByVal success As Boolean) |
26 | | - On Error GoTo App_WorkbookAfterSave_Error |
27 | | - |
28 | | - 'Export all the modules for this work book if save was successful |
29 | | - If success Then |
30 | | - Build.exportVbaCode wb.VBProject |
31 | | - NamedRanges.exportNamedRanges wb |
32 | | - MsgBox "Finished saving workbook: " & wb.name & " . Code is exported." |
33 | | - Else |
34 | | - MsgBox "Saving workbook: " & wb.name & " was not successful. Code is not exported." |
35 | | - End If |
36 | | - |
37 | | - Exit Sub |
38 | | -App_WorkbookAfterSave_Error: |
39 | | - ErrorHandling.handleError "vbaDeveloper.EventListener afterSave" |
40 | | -End Sub |
41 | | - |
42 | | - |
43 | | -Private Sub App_WorkbookBeforeSave(ByVal wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean) |
44 | | - If Not Cancel Then |
45 | | - Formatter.formatProject wb.VBProject |
46 | | - End If |
47 | | -End Sub |
48 | | - |
49 | | - |
50 | | -Private Sub App_WorkbookOpen(ByVal wb As Workbook) |
51 | | - On Error GoTo App_WorkbookOpen_Error |
52 | | - |
53 | | - 'Import all the modules for this workbook |
54 | | - Dim importNow As Integer |
55 | | - importNow = MsgBox("Import the code for " & wb.name & " now?", vbYesNo, "EventListener Workbook open event") |
56 | | - If importNow = vbYes Then |
57 | | - Build.importVbaCode wb.VBProject |
58 | | - NamedRanges.importNamedRanges wb |
59 | | - End If |
60 | | - |
61 | | - Exit Sub |
62 | | -App_WorkbookOpen_Error: |
63 | | - ErrorHandling.handleError "vbaDeveloper.EventListener WorkbookOpen" |
64 | | -End Sub |
65 | | - |
66 | | - |
67 | | -Private Sub Class_Terminate() |
68 | | - Set App = Nothing |
69 | | -End Sub |
70 | | - |
| 1 | +VERSION 1.0 CLASS |
| 2 | +BEGIN |
| 3 | + MultiUse = -1 'True |
| 4 | +END |
| 5 | +Attribute VB_Name = "EventListener" |
| 6 | +Attribute VB_GlobalNameSpace = False |
| 7 | +Attribute VB_Creatable = False |
| 8 | +Attribute VB_PredeclaredId = False |
| 9 | +Attribute VB_Exposed = False |
| 10 | +Option Explicit |
| 11 | + |
| 12 | +'This class receives and acts upon events from the excel application. |
| 13 | +' To disable this eventhandling, simply don't instantiate this class. See Thisworkbook. |
| 14 | + |
| 15 | + |
| 16 | +Private WithEvents App As Application |
| 17 | +Attribute App.VB_VarHelpID = -1 |
| 18 | + |
| 19 | + |
| 20 | +Private Sub Class_Initialize() |
| 21 | + Set App = Application |
| 22 | +End Sub |
| 23 | + |
| 24 | + |
| 25 | +Private Sub App_WorkbookAfterSave(ByVal wb As Workbook, ByVal success As Boolean) |
| 26 | + On Error GoTo App_WorkbookAfterSave_Error |
| 27 | + |
| 28 | + 'Export all the modules for this work book if save was successful |
| 29 | + If success Then |
| 30 | + Build.exportVbaCode wb.VBProject |
| 31 | + NamedRanges.exportNamedRanges wb |
| 32 | + MsgBox "Finished saving workbook: " & wb.name & " . Code is exported." |
| 33 | + Else |
| 34 | + MsgBox "Saving workbook: " & wb.name & " was not successful. Code is not exported." |
| 35 | + End If |
| 36 | + |
| 37 | + Exit Sub |
| 38 | +App_WorkbookAfterSave_Error: |
| 39 | + ErrorHandling.handleError "vbaDeveloper.EventListener afterSave" |
| 40 | +End Sub |
| 41 | + |
| 42 | + |
| 43 | +Private Sub App_WorkbookBeforeSave(ByVal wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean) |
| 44 | + If Not Cancel Then |
| 45 | + Formatter.formatProject wb.VBProject |
| 46 | + End If |
| 47 | +End Sub |
| 48 | + |
| 49 | + |
| 50 | +Private Sub App_WorkbookOpen(ByVal wb As Workbook) |
| 51 | + On Error GoTo App_WorkbookOpen_Error |
| 52 | + |
| 53 | + 'Import all the modules for this workbook |
| 54 | + Dim importNow As Integer |
| 55 | + importNow = MsgBox("Import the code for " & wb.name & " now?", vbYesNo, "EventListener Workbook open event") |
| 56 | + If importNow = vbYes Then |
| 57 | + Build.importVbaCode wb.VBProject |
| 58 | + NamedRanges.importNamedRanges wb |
| 59 | + End If |
| 60 | + |
| 61 | + Exit Sub |
| 62 | +App_WorkbookOpen_Error: |
| 63 | + ErrorHandling.handleError "vbaDeveloper.EventListener WorkbookOpen" |
| 64 | +End Sub |
| 65 | + |
| 66 | + |
| 67 | +Private Sub Class_Terminate() |
| 68 | + Set App = Nothing |
| 69 | +End Sub |
| 70 | + |
0 commit comments