Skip to content

Commit 21320c4

Browse files
committed
Install: + register menu add-in
1 parent 99931ac commit 21320c4

File tree

1 file changed

+86
-22
lines changed

1 file changed

+86
-22
lines changed

access-add-in/AccUnitLoader_Install.vbs

Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,43 @@ const AddInName = "ACLib-AccUnit-Loader"
22
const AddInFileName = "AccUnitLoader.accda"
33
const MsgBoxTitle = "Update ACLib-AccUnit-Loader"
44

5+
Dim AddInFileInstalled, CompletedMsg
6+
57
MsgBox "Before updating the add-in file, the add-in must not be loaded!" & chr(13) & _
6-
"For safety, close all Access instances.", , MsgBoxTitle & ": Hinweis"
8+
"For safety, close all Access instances.", , MsgBoxTitle & ": Information"
79

8-
Select Case MsgBox("Should the add-in be used as ACCDE?" + chr(13) & _
10+
Select Case MsgBox("Should the add-in be used as a compiled file (accde)?" + chr(13) & _
911
"(Add-In is compiled and copied to the Add-In directory.)", 3, MsgBoxTitle)
1012
case 6 ' vbYes
11-
if CreateMde(GetSourceFileFullName, GetDestFileFullName) = True then
12-
MsgBox "Compiled file was created.", , MsgBoxTitle
13-
else
14-
MsgBox "Error! Compiled file was not created.", , MsgBoxTitle
15-
end if
13+
AddInFileInstalled = CreateMde(GetSourceFileFullName, GetDestFileFullName)
14+
If AddInFileInstalled Then
15+
CompletedMsg = "Add-In was compiled and saved in '" + GetAddInLocation + "'."
16+
Else
17+
CompletedMsg = "Error! Compiled file was not created."
18+
End If
1619
case 7 ' vbNo
1720
DeleteAddInFiles
18-
if CopyFileAndRundPrecompileProc(GetSourceFileFullName, GetDestFileFullName) Then
19-
MsgBox "File was copied.", , MsgBoxTitle
20-
else
21-
MsgBox "Error! File was not copied.", , MsgBoxTitle
22-
end if
21+
AddInFileInstalled = CopyFileAndRundPrecompileProc(GetSourceFileFullName, GetDestFileFullName)
22+
If AddInFileInstalled Then
23+
CompletedMsg = "Add-In was saved in '" + GetAddInLocation + "'."
24+
Else
25+
CompletedMsg = "Error! File was not copied."
26+
End If
2327
case else
2428

2529
End Select
2630

31+
If AddInFileInstalled = True Then
32+
RegisterAddIn GetDestFileFullName()
33+
End If
34+
35+
If CompletedMsg > "" Then
36+
MsgBox CompletedMsg, , MsgBoxTitle
37+
End If
38+
2739

2840
'##################################################
29-
' Hilfsfunktionen:
41+
' Functions
3042

3143
Function GetSourceFileFullName()
3244
GetSourceFileFullName = GetScriptLocation & AddInFileName
@@ -37,38 +49,29 @@ Function GetDestFileFullName()
3749
End Function
3850

3951
Function GetScriptLocation()
40-
4152
With WScript
4253
GetScriptLocation = Replace(.ScriptFullName & ":", .ScriptName & ":", "")
4354
End With
44-
4555
End Function
4656

4757
Function GetAddInLocation()
48-
4958
GetAddInLocation = GetAppDataLocation & "Microsoft\AddIns\"
50-
5159
End Function
5260

5361
Function GetAppDataLocation()
54-
5562
Set wsShell = CreateObject("WScript.Shell")
5663
GetAppDataLocation = wsShell.ExpandEnvironmentStrings("%APPDATA%") & "\"
57-
5864
End Function
5965

6066
Function FileCopy(SourceFilePath, DestFilePath)
61-
Set AccessApp = CreateObject("Access.Application")
6267
set fso = CreateObject("Scripting.FileSystemObject")
6368
fso.CopyFile SourceFilePath, DestFilePath
6469
FileCopy = True
6570
End Function
6671

6772
Function DeleteAddInFiles()
68-
6973
Set fso = CreateObject("Scripting.FileSystemObject")
7074
DeleteAddInFilesFso fso
71-
7275
End Function
7376

7477
Function DeleteAddInFilesFso(fso)
@@ -143,3 +146,64 @@ Function RunPrecompileProcedure(AccessApp, SourceFilePath)
143146
RunPrecompileProcedure = True
144147

145148
End Function
149+
150+
151+
'##################################################
152+
' Register Menu Add-In
153+
154+
Function RegisterAddIn(AddInFile)
155+
156+
Dim AddInDb, AccessApp, rst, ItemValue, wsh
157+
158+
Set AccessApp = CreateObject("Access.Application")
159+
Set AddInDb = AccessApp.DBEngine.OpenDatabase(AddInFile)
160+
161+
set wsh = CreateObject("WScript.Shell")
162+
Set rst = AddInDb.OpenRecordset("select Subkey, ValName, Type, Value from USysRegInfo where ValName > '' Order By ValName", 8) 'dbOpenForwardOnly=8
163+
Do While Not rst.EOF
164+
ItemValue = rst.Fields("Value").Value
165+
If Len(ItemValue) > 0 Then
166+
If InStr(1, ItemValue, "|ACCDIR") > 0 Then
167+
ItemValue = AddInDb.Name
168+
End If
169+
End If
170+
RegisterMenuAddInItem AccessApp, wsh, rst.Fields("Subkey").Value, rst.Fields("ValName").Value, rst.Fields("Type").Value, ItemValue
171+
rst.MoveNext
172+
Loop
173+
rst.Close
174+
175+
AddInDb.Close
176+
177+
End Function
178+
179+
Function RegisterMenuAddInItem(AccessApp, wsh, ByVal SubKey, ByVal ItemValName, ByVal RegType, ByVal ItemValue)
180+
Dim RegName
181+
RegName = GetRegistryPath(SubKey, AccessApp)
182+
With wsh
183+
If Len(ItemValName) > 0 Then
184+
RegName = RegName & "\" & ItemValName
185+
End If
186+
.RegWrite RegName, ItemValue, GetRegTypeString(RegType)
187+
End With
188+
End Function
189+
190+
Function GetRegTypeString(ByVal RegType)
191+
Select Case RegType
192+
Case 1
193+
GetRegTypeString = "REG_SZ"
194+
Case 4
195+
GetRegTypeString = "REG_DWORD"
196+
Case 0
197+
GetRegTypeString = vbNullString
198+
Case Else
199+
Err.Raise vbObjectError, "GetRegTypeString", "RegType not supported"
200+
End Select
201+
End Function
202+
203+
Function GetRegistryPath(SubKey, AccessApp)
204+
GetRegistryPath = Replace(SubKey, "HKEY_CURRENT_ACCESS_PROFILE", HkeyCurrentAccessProfileRegistryPath(AccessApp))
205+
End Function
206+
207+
Function HkeyCurrentAccessProfileRegistryPath(AccessApp)
208+
HkeyCurrentAccessProfileRegistryPath = "HKCU\SOFTWARE\Microsoft\Office\" & AccessApp.Version & "\Access"
209+
End Function

0 commit comments

Comments
 (0)