Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit f55c884

Browse files
committed
some fixes
1 parent 30b98d6 commit f55c884

8 files changed

+76
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
~$*

Class Modules/TocSheetAppEventHandler.cls

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ Attribute AppEvent.VB_VarHelpID = -1
1515

1616
'handles changes in the Toc sheet (update custom properties if edited manually)
1717
Private Sub AppEvent_SheetChange(ByVal Sh As Object, ByVal Target As Range)
18+
On Error GoTo Hoppla
19+
'called from toc handler
20+
If isF5 Then Exit Sub
21+
'error...
22+
If Sh Is Nothing Then Exit Sub
1823

1924
'not a worksheet?
2025
If Not TypeOf Sh Is Worksheet Then Exit Sub
21-
'not Toc page?
22-
If Sh.Name <> getTocSheetName() Then Exit Sub
26+
27+
'parent not a workbook
28+
If Not TypeOf Sh.Parent Is Workbook Then Exit Sub
29+
2330
'is there already a table? If not -> just exit sub
2431
If Sh.ListObjects.count = 0 Then Exit Sub
2532

26-
If isF5 Then Exit Sub
27-
33+
'not Toc page? (last check because in worstcase it iterates all worksheets)
34+
If Sh.Name <> getTocSheetName() Then Exit Sub
35+
2836
Dim cl As Range
2937

3038
Dim arrIdxCols As Variant
@@ -73,7 +81,7 @@ Private Sub AppEvent_SheetChange(ByVal Sh As Object, ByVal Target As Range)
7381
End If
7482

7583
Skip:
76-
On Error GoTo 0
84+
On Error GoTo Hoppla
7785
Next cl
7886

7987

@@ -96,19 +104,23 @@ If Right(newCusProp, 1) = ";" Then newCusProp = Left(newCusProp, Len(newCusProp)
96104
setProperty Sh, "TocColumns", Join(arrIdxCols, ";")
97105
setProperty Sh, "TocCustomProperties", newCusProp
98106

99-
107+
Hoppla:
100108
Application.ScreenUpdating = True
101109
Application.DisplayAlerts = True
102110
End Sub
103111

104112
'constructor:
105113
Public Sub Class_Initialize()
114+
On Error GoTo Hoppla
106115
'bind events from "Application" to this class var "AppEvent"
107116
Set AppEvent = Application
117+
Hoppla:
108118
End Sub
109119

110120
' New WorkBook added in Application: with it also the first WorkSheet was created
111121
Private Sub AppEvent_NewWorkbook(ByVal WB As Workbook)
122+
On Error GoTo Hoppla
123+
112124
Dim cPrpNm As String
113125
cPrpNm = getWorksheetCreatedDatePropName()
114126

@@ -118,10 +130,14 @@ Private Sub AppEvent_NewWorkbook(ByVal WB As Workbook)
118130
End If
119131

120132
setProperty WB.Sheets(1), "isToc", "0"
133+
134+
Hoppla:
135+
121136
End Sub
122137

123138
' new WorkSheet added
124139
Private Sub AppEvent_WorkbookNewSheet(ByVal WB As Workbook, ByVal Sh As Object)
140+
On Error GoTo Hoppla
125141
If Not TypeOf Sh Is Worksheet Then Exit Sub
126142
Dim cPrpNm As String
127143
cPrpNm = getWorksheetCreatedDatePropName()
@@ -136,11 +152,12 @@ cPrpNm = getWorksheetCreatedDatePropName()
136152
If worksheetExists(WB, getTocSheetName()) Then
137153
Call generateTocWorksheet
138154
End If
139-
155+
Hoppla:
140156
End Sub
141157

142158
'refresh table of contents sheet if activated
143159
Private Sub AppEvent_SheetActivate(ByVal Sh As Object)
160+
On Error GoTo Hoppla
144161
'not a worksheet?
145162
If Not TypeOf Sh Is Worksheet Then Exit Sub
146163
'not a workbook?
@@ -152,8 +169,9 @@ Private Sub AppEvent_SheetActivate(ByVal Sh As Object)
152169

153170
'there is no sheet for table of contents?
154171
If Not worksheetExists(Sh.Parent, idx) Then Exit Sub
155-
172+
156173
If Sh.Name = idx Then
157174
Call generateTocWorksheet
158175
End If
176+
Hoppla:
159177
End Sub

DieseArbeitsmappe.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Attribute VB_GlobalNameSpace = False
77
Attribute VB_Creatable = False
88
Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = True
10-
'' Source can be found at https://gitlab.com/haenggli.net/excel/tableofcontents-generator-addin
10+
'' Source can be found at https://github.com/ahaenggli/Excel-PlugIn-TableOfContents
1111

1212
Option Explicit
1313

@@ -23,11 +23,11 @@ Private Sub Workbook_Open()
2323

2424
'' CTRL + Shift + A
2525
'Application.OnKey "^+{A}", "tstBox"
26-
Application.OnKey "{F5}", "handleF5Click"
26+
Application.OnKey getGlobalTocHandlerPropName(), "handleF5Click"
2727
isF5 = False
2828
'init application wide event handler
2929
Set TocSheetExtension_AppEventHandler = New TocSheetAppEventHandler
30-
30+
3131
End Sub
3232

3333

Forms/PropertyExtensionForm.frx

0 Bytes
Binary file not shown.

Forms/TocSheetExtensionForm.frm

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
VERSION 5.00
22
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} TocSheetExtensionForm
33
Caption = "edit custom values for index sheet"
4-
ClientHeight = 3420
4+
ClientHeight = 4590
55
ClientLeft = 120
66
ClientTop = 465
7-
ClientWidth = 6555
7+
ClientWidth = 6435
88
OleObjectBlob = "TocSheetExtensionForm.frx":0000
99
StartUpPosition = 1 'Fenstermitte
1010
End
@@ -28,7 +28,8 @@ Private Sub UserForm_Activate()
2828
txtProperties.Text = Join(getTocCustomProperties(), ";")
2929
txtSummaryColumns.Text = Join(getTocColumns(), ";")
3030
txtWorkSheetCreatedDate.Text = getWorksheetCreatedDatePropName()
31-
31+
txtCallToc.Text = getGlobalTocHandlerPropName()
32+
3233
If Not worksheetExists(ActiveWorkbook, getTocSheetName()) Then
3334
Me.cbSetDefault.Value = True
3435
End If
@@ -39,18 +40,19 @@ Private Sub saveSettings()
3940
If Not worksheetExists(ActiveWorkbook, getTocSheetName()) And Me.cbSetDefault.Value = False Then
4041
Call generateTocWorksheet
4142
End If
42-
43-
If worksheetExists(ActiveWorkbook, getTocSheetName()) Then
44-
setProperty ActiveWorkbook.Worksheets(1), "TocWorksheetName", txtSumTitel.Text
45-
setProperty ActiveWorkbook.Worksheets(1), "TocCustomProperties", txtProperties.Text
46-
setProperty ActiveWorkbook.Worksheets(1), "TocColumns", txtSummaryColumns.Text
47-
setProperty ActiveWorkbook.Worksheets(1), "WorksheetCreatedDatePropName", txtWorkSheetCreatedDate.Text
43+
44+
If worksheetExists(ActiveWorkbook, getTocSheetName()) And Me.cbSetDefault.Value = False Then
45+
If txtSumTitel.Text <> "" Then setProperty ActiveWorkbook.Worksheets(1), "TocWorksheetName", txtSumTitel.Text
46+
If txtProperties.Text <> "" Then setProperty ActiveWorkbook.Worksheets(1), "TocCustomProperties", txtProperties.Text
47+
If txtSummaryColumns.Text <> "" Then setProperty ActiveWorkbook.Worksheets(1), "TocColumns", txtSummaryColumns.Text
4848

49-
On Error Resume Next
50-
Application.DisplayAlerts = False
51-
ActiveWorkbook.Save
52-
Application.DisplayAlerts = True
53-
On Error GoTo 0
49+
setProperty ActiveWorkbook.Worksheets(1), "WorksheetCreatedDatePropName", txtWorkSheetCreatedDate.Text
50+
51+
On Error Resume Next
52+
Application.DisplayAlerts = False
53+
ActiveWorkbook.Save
54+
Application.DisplayAlerts = True
55+
On Error GoTo 0
5456
End If
5557

5658
If Me.cbSetDefault.Value = True Then
@@ -59,11 +61,17 @@ Private Sub saveSettings()
5961
' -> ThisWorkbook is where the code is saved (xlam-file)
6062
' -> even a xlam file has at least one sheet
6163
' -> here it's named "TocConfig"
62-
setProperty ThisWorkbook.Worksheets(1), "TocWorksheetName", txtSumTitel.Text
63-
setProperty ThisWorkbook.Worksheets(1), "TocCustomProperties", txtProperties.Text
64-
setProperty ThisWorkbook.Worksheets(1), "TocColumns", txtSummaryColumns.Text
65-
setProperty ThisWorkbook.Worksheets(1), "WorksheetCreatedDatePropName", txtWorkSheetCreatedDate.Text
64+
If txtSumTitel.Text <> "" And txtSumTitel.Text <> getTocSheetName() Then setProperty ThisWorkbook.Worksheets(1), "TocWorksheetName", txtSumTitel.Text
65+
If txtProperties.Text <> "" And txtProperties.Text <> Join(getTocCustomProperties(), ";") Then setProperty ThisWorkbook.Worksheets(1), "TocCustomProperties", txtProperties.Text
66+
If txtSummaryColumns.Text <> "" And txtSummaryColumns.Text <> Join(getTocColumns(), ";") Then setProperty ThisWorkbook.Worksheets(1), "TocColumns", txtSummaryColumns.Text
67+
If txtWorkSheetCreatedDate.Text <> getWorksheetCreatedDatePropName() Then setProperty ThisWorkbook.Worksheets(1), "WorksheetCreatedDatePropName", txtWorkSheetCreatedDate.Text
6668

69+
If txtCallToc.Text <> "" And txtCallToc.Text <> getGlobalTocHandlerPropName() Then
70+
Application.OnKey getGlobalTocHandlerPropName()
71+
setProperty ThisWorkbook.Worksheets(1), "GlobalTocHandlerPropName", txtCallToc.Text
72+
Application.OnKey getGlobalTocHandlerPropName(), "handleF5Click"
73+
End If
74+
6775
On Error Resume Next
6876
Application.DisplayAlerts = False
6977
ThisWorkbook.Save

Forms/TocSheetExtensionForm.frx

512 Bytes
Binary file not shown.

Modules/TocSheetExtension.bas

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ Public Sub handleF5Click()
1515
isF5 = False
1616
End Sub
1717

18+
'get the name for the global toc handler (default: F5) (custom property)
19+
Public Function getGlobalTocHandlerPropName() As String
20+
Dim prop As String
21+
prop = ""
22+
23+
On Error Resume Next
24+
' only global possible
25+
If prop = "" Then prop = getProperty(ThisWorkbook.Worksheets(1), "GlobalTocHandlerPropName")
26+
If prop = "" Then prop = "{F5}"
27+
28+
If Err.Number > 0 Then
29+
prop = "{F5}"
30+
Err.Clear
31+
End If
32+
On Error GoTo 0
33+
34+
getGlobalTocHandlerPropName = prop
35+
End Function
36+
37+
1838
'get the name for the worksheet created field (custom property)
1939
Public Function getWorksheetCreatedDatePropName() As String
2040
Dim prop As String
8.59 KB
Binary file not shown.

0 commit comments

Comments
 (0)