-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmod_WordVarStorage.bas
48 lines (37 loc) · 1.43 KB
/
mod_WordVarStorage.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Attribute VB_Name = "mod_WordVarStorage"
Option Explicit
Public ListBoxItems() As String
Private Sub Example()
Call PokeVar("ListBoxItems", "Item1,Item2,Item3,Item4")
ListBoxItems = Split(PeekVar("ListBoxItems"), ",")
MsgBox ListBoxItems(2)
End Sub
Private Function PokeVar(ByVal VariableName As String, ByVal VariableData As String) As Variable
Dim VariableObject As Variable
For Each VariableObject In ActiveDocument.Variables
If VariableObject.Name = VariableName Then
VariableObject.Value = VariableData
PokeVar = VariableObject.Index
Exit Function
End If
Next VariableObject
ActiveDocument.Variables.Add Name:=VariableName, Value:=VariableData
End Function
Private Function PeekVar(ByVal VariableName As String) As String
Dim VariableObject As Variable
For Each VariableObject In ActiveDocument.Variables
If VariableObject.Name = VariableName Then
PeekVar = VariableObject.Value
End If
Next VariableObject
End Function
Private Function DelVar(ByVal VariableName As String) As Boolean
Dim VariableObject As Variable
DelVar = False
For Each VariableObject In ActiveDocument.Variables
If VariableObject.Name = VariableName Then
VariableObject.Delete
DelVar = True
End If
Next VariableObject
End Function