forked from Azure/review-checklists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSheet1.cls
643 lines (621 loc) · 28.2 KB
/
Sheet1.cls
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Sheet1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Option Explicit
Option Base 0
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Const line_break = vbCrLf
Const category_column = 1
Const subcategory_column = 2
Const text_column = 3
Const description_column = 4
Const severity_column = 5
Const status_column = 6
Const comments_column = 7
Const link_column = 8
Const training_column = 9
Const graph_success_column = 10
Const graph_failure_column = 11
Const guid_column = 12
Const checklist_name_row = 2
Const checklist_name_col = 1
Const values_sheet = "values"
Const values_sev_column = 1
Const values_status_column = 2
Const values_category_column = 3
Const row1 = 5
Const row_limit = 2000 'Safety net
Dim selected_language As String
Dim selected_technology As String
Dim import_graph_queries As Boolean
'Modifies text so that it can be stored in JSON format
' * Removes line breaks (chr10 and chr13)
' * Replaces doublequotes with single quotes
' * Eliminates blanks (replaces with  )
Function correct_format_for_JSON(ByVal input_text As String) As String
'Remove breaks
input_text = Replace(Replace(input_text, Chr(10), ""), Chr(13), "")
'Replace double quotes with single quotes
input_text = Replace(input_text, Chr(34), Chr(39))
'If it is a link, remove localization
input_text = Replace(input_text, "en-us/", "")
'Escape control characters such as "?"
'input_text = escape_character(input_text, "?")
'Avoid empty fields, the Azure translate API doesnt work well with then
If input_text = "" Then input_text = " "
correct_format_for_JSON = input_text
End Function
'Escapes a character in a string, and gives out the resulting string
Function escape_character(ByVal input_text As String, search_char As String) As String
'First we remove any possible escape signs for that character that might be already there
input_text = Replace(input_text, "\?", "?")
'Now we escape all occurrences of the character
input_text = Replace(input_text, "?", "\?")
'And return the output
escape_character = input_text
End Function
'Exports current checklist from excel to a json-formated text file
Sub export_json()
On Error GoTo errh
' Constants
Const export_file_name = "checklist.json"
Const values_sheet = "values"
Const values_category_column = 3
' Variables
Dim row As Integer
Dim json As String
Dim check_category, check_subcategory, check_text, check_description, check_severity, check_status, check_link, check_training, check_graph_success, check_graph_failure, check_guid As String
Dim category_name, severity_name, status_name As String
Dim export_file_path As Variant
Dim double_quote As String
Dim item_count, category_count, status_count As Integer
' Initialization
double_quote = Chr(34) ' double quote as a variable
row = row1
json = "{" + line_break
json = json + " " + double_quote + "items" + double_quote + ": ["
item_count = 0
category_count = 0
status_count = 0
' Loop through all rows as long as there is content
Do While row < row_limit And Len(Cells(row, category_column)) > 0
If row > row1 Then json = json + ","
json = json + line_break
check_category = Cells(row, category_column)
check_subcategory = Cells(row, subcategory_column)
check_text = Cells(row, text_column)
check_description = Cells(row, description_column)
check_severity = Cells(row, severity_column)
check_graph_success = Cells(row, graph_success_column)
check_graph_failure = Cells(row, graph_failure_column)
check_guid = Cells(row, guid_column)
'If there was no GUID, generate one
If Len(check_guid) = 0 Then check_guid = generate_guid()
'Only read More Info hyperlink if the cell contains one
If Cells(row, link_column).Hyperlinks.Count > 0 Then
check_link = Cells(row, link_column).Hyperlinks(1).Address
Else
check_link = Cells(row, link_column)
End If
'Only read Training hyperlink if the cell contains one
If Cells(row, training_column).Hyperlinks.Count > 0 Then
check_training = Cells(row, training_column).Hyperlinks(1).Address
Else
check_training = Cells(row, training_column)
End If
row = row + 1
json = json + " {" + line_break
json = json + " " + double_quote + "category" + double_quote + ": " + double_quote + correct_format_for_JSON(check_category) + double_quote + ","
json = json + line_break + " " + double_quote + "subcategory" + double_quote + ": " + double_quote + correct_format_for_JSON(check_subcategory) + double_quote
json = json + "," + line_break + " " + double_quote + "text" + double_quote + ": " + double_quote + correct_format_for_JSON(check_text) + double_quote
If Len(check_description) > 0 Then json = json + "," + line_break + " " + double_quote + "description" + double_quote + ": " + double_quote + correct_format_for_JSON(check_description) + double_quote
If Len(check_guid) > 0 Then json = json + "," + line_break + " " + double_quote + "guid" + double_quote + ": " + double_quote + check_guid + double_quote
If Len(check_severity) > 0 Then json = json + "," + line_break + " " + double_quote + "severity" + double_quote + ": " + double_quote + check_severity + double_quote
If Len(check_graph_success) > 0 Then json = json + "," + line_break + " " + double_quote + "graph_success" + double_quote + ": " + double_quote + check_graph_success + double_quote
If Len(check_graph_failure) > 0 Then json = json + "," + line_break + " " + double_quote + "graph_failure" + double_quote + ": " + double_quote + check_graph_failure + double_quote
If Len(check_training) > 0 Then json = json + "," + line_break + " " + double_quote + "training" + double_quote + ": " + double_quote + correct_format_for_JSON(check_training) + double_quote
If Len(check_link) > 0 Then json = json + "," + line_break + " " + double_quote + "link" + double_quote + ": " + double_quote + correct_format_for_JSON(check_link) + double_quote
json = json + line_break + " }"
item_count = item_count + 1
Loop
' Finish items section
json = json + line_break + " ]," + line_break
' Create categories section
json = json + " " + double_quote + "categories" + double_quote + ": ["
row = 2
Do While row < row_limit And Len(Sheets(values_sheet).Cells(row, values_category_column)) > 0
If row > 2 Then json = json + ","
json = json + line_break
category_name = Sheets(values_sheet).Cells(row, values_category_column)
json = json + " {" + line_break
json = json + " " + double_quote + "name" + double_quote + ": " + double_quote + correct_format_for_JSON(category_name) + double_quote + line_break
json = json + " }"
row = row + 1
category_count = category_count + 1
Loop
' Finish category section
json = json + line_break + " ]," + line_break
' Create status section
json = json + " " + double_quote + "status" + double_quote + ": ["
row = 2
Do While row < row_limit And Len(Sheets(values_sheet).Cells(row, values_status_column)) > 0
If row > 2 Then json = json + ","
json = json + line_break
status_name = Sheets(values_sheet).Cells(row, values_status_column)
json = json + " {" + line_break
json = json + " " + double_quote + "name" + double_quote + ": " + double_quote + correct_format_for_JSON(status_name) + double_quote + line_break
json = json + " }"
row = row + 1
status_count = status_count + 1
Loop
' Finish status section
json = json + line_break + " ]," + line_break
' Create severities section
json = json + " " + double_quote + "severities" + double_quote + ": ["
row = 2
Do While row < row_limit And Len(Sheets(values_sheet).Cells(row, values_sev_column)) > 0
If row > 2 Then json = json + ","
json = json + line_break
severity_name = Sheets(values_sheet).Cells(row, values_sev_column)
json = json + " {" + line_break
json = json + " " + double_quote + "name" + double_quote + ": " + double_quote + correct_format_for_JSON(severity_name) + double_quote + line_break
json = json + " }"
row = row + 1
Loop
' Finish severities section
json = json + line_break + " ]," + line_break
' Create metadata section
json = json + " " + double_quote + "metadata" + double_quote + ": {" + line_break
json = json + " " + double_quote + "name" + double_quote + ": " + double_quote + correct_format_for_JSON(Cells(checklist_name_row, checklist_name_col)) + double_quote + line_break
' Finish metadata section
json = json + " }" + line_break
' Finish JSON
json = json + "}" + line_break
' Write JSON to file
' MsgBox json
'export_file_path = ActiveWorkbook.Path + "\" + export_file_name
export_file_path = ""
export_file_path = Application.GetSaveAsFilename(FileFilter:="JSON File (*.json), *.json", Title:="Exporting JSON checklist", InitialFileName:=ActiveWorkbook.Path + "\" + export_file_name)
'checks to make sure the user hasn't canceled the dialog
If export_file_path <> False Then
'MsgBox "Exporting to " + export_file_path
Open export_file_path For Output As #1
Print #1, json
Close #1
End If
MsgBox CStr(item_count) + " checklist items and " + CStr(category_count) + " categories exported to JSON file " + export_file_path, vbInformation
Exit Sub
errh:
If Err.Number <> 0 Then
MsgBox "Error while exporting checklist to JSON " & Err.Description, vbCritical
End If
End Sub
'Import JSON from URL (first download to a local file)
Sub import_checklist_fromurl()
Const values_sheet = "values"
Const values_url_column = 4
Dim checklist_url, checklist_base_url As String
Dim json_file As Variant
Dim buf, ret As Long
Dim url_split() As String
Dim filename As String
Dim objXmlHttpReq As Object
Dim objStream As Object
Dim msg As String
'Get URL stored in the Values sheet
checklist_base_url = Sheets(values_sheet).Cells(2, values_url_column)
If Len(checklist_base_url) > 0 Then
'Look at the option buttons to set global variables that control technology (LZ, AKS, AVD) and language
set_checklist_variables
'Append the technology and options variables (default to English and LZ)
If Len(selected_technology) = 0 Then selected_technology = "lz"
If Len(selected_language) = 0 Then selected_language = "en"
checklist_url = checklist_base_url + selected_technology + "_checklist." + selected_language + ".json"
'Get the filename of the URL
url_split = Split(checklist_url, "/")
filename = url_split(UBound(url_split))
' Instead of letting the user specify a download directory, picking up Downloads per default
'ChDir ActiveWorkbook.Path
'json_file = Application.GetOpenFilename(Title:="Please choose a file to open", FileFilter:="JSON Files *.json* (*.json),")
json_file = Environ("USERPROFILE") + "\Downloads\checklist.json"
msg = "Reference checklist will be downloaded from '" + checklist_url + "' to '" + CStr(json_file) + "'"
If MsgBox(msg, vbOKCancel + vbQuestion, "Downloading reference checklist") = vbOK Then
ret = URLDownloadToFile(0, checklist_url, json_file, 0, 0)
If ret = 0 Then
'Call the sub for actually doing the import
import_checklist_fromfile json_file
Else
MsgBox "Checklist could not be downloaded from '" + checklist_url + "'", vbCritical
End If
End If
Else
MsgBox "Sorry, I could not found out the reference URL in sheet '" + values_sheet + "' at cell location 2," + CStr(values_url_column), vbCritical
End If
End Sub
'Import from custom JSON file
Sub import_checklist()
Dim json_file As Variant
ChDir ActiveWorkbook.Path
json_file = Application.GetOpenFilename(Title:="Please choose a file to open", FileFilter:="JSON Files *.json* (*.json),")
If json_file = False Then
MsgBox "No file selected.", vbExclamation, "Action canceled"
Exit Sub
Else
import_graph_queries = True 'Always import graph queries in advanced mode.
import_checklist_fromfile json_file
End If
End Sub
'Import from a local JSON file
'Parse JSON code using the JsonConverter module
Sub import_checklist_fromfile(json_file As Variant)
On Error GoTo errh
' Constants
Const row1 = 5
Const row_limit = 2000 'Safety net
'Variables
Dim json_ts As TextStream
Dim FSO As New FileSystemObject
Dim textline As String
Dim json As String
Dim json_object, json_item As Object
Dim double_quote As String
Dim line_elements() As String
Dim row, item_count, category_count, status_count, i As Integer
Dim notverified As String
'Initialization
row = row1
double_quote = Chr(34) ' double quote as a variable
json = ""
item_count = 0
category_count = 0
status_count = 0
'Go through the file line by line
' Read .json file with FSO.OpenTextFile
'Set json_ts = FSO.OpenTextFile(json_file, ForReading)
'json = json_ts.ReadAll
'json_ts.Close
'Read .json file as object stream
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "utf-8"
objStream.Open
objStream.LoadFromFile (json_file)
json = objStream.ReadText()
objStream.Close
Set objStream = Nothing
json = Replace(json, vbCrLf, "")
Set json_object = JsonConverter.ParseJson(json) 'This line might give Run-time error 10001 if there are JSON syntactic errors
'Update checklist title
If json_object.Exists("metadata") Then
If json_object("metadata").Exists("name") Then
Cells(checklist_name_row, checklist_name_col) = json_object("metadata")("name")
End If
End If
'Import status
If json_object.Exists("status") Then
row = 2
If TypeName(json_object("status")) = "Dictionary" Then
notverified = json_object("status")("0")("name") ' The "Not Verified" status is the first one
i = 0
Do
Sheets(values_sheet).Cells(row, values_status_column) = json_object("status")(CStr(i))("name")
row = row + 1
status_count = status_count + 1
i = i + 1
Loop While json_object("status").Exists(CStr(i))
Else
notverified = json_object("status")(1)("name") ' The "Not Verified" status is the first one
For Each json_item In json_object("status")
Sheets(values_sheet).Cells(row, values_status_column) = json_item("name")
row = row + 1
status_count = status_count + 1
Next json_item
End If
'Blank the rest of the status rows, although for status this shouldnt be required
Do While row < row_limit And Len(Cells(row, values_status_column)) > 0
Sheets(values_sheet).Cells(row, values_status_column) = ""
row = row + 1
Loop
End If
'Import checklist items
row = row1
'If JSON is a translated file, it is a nested dictionary with keys "0", "1", etc
If TypeName(json_object("items")) = "Dictionary" Then
i = 0
Do
update_row json_object("items")(CStr(i)), row, notverified
row = row + 1
item_count = item_count + 1
i = i + 1
Loop While json_object("items").Exists(CStr(i))
'Otherwise, it is just an array
Else
For Each json_item In json_object("items")
update_row json_item, row, notverified
row = row + 1
item_count = item_count + 1
Next json_item
End If
'Blank the rest of the item rows
Do While row < row_limit And (Len(Cells(row, category_column)) + Len(Cells(row, subcategory_column)) + Len(Cells(row, text_column)) + Len(Cells(row, status_column)) + Len(Cells(row, comments_column))) > 0
Cells(row, category_column) = ""
Cells(row, subcategory_column) = ""
Cells(row, text_column) = ""
Cells(row, description_column) = ""
Cells(row, severity_column) = ""
Cells(row, link_column) = ""
Cells(row, status_column) = ""
Cells(row, comments_column) = ""
Cells(row, training_column) = ""
Cells(row, graph_success_column) = ""
Cells(row, graph_failure_column) = ""
row = row + 1
Loop
'Import categories
If json_object.Exists("categories") Then
row = 2
If TypeName(json_object("categories")) = "Dictionary" Then
i = 0
Do
Sheets(values_sheet).Cells(row, values_category_column) = json_object("categories")(CStr(i))("name")
row = row + 1
category_count = category_count + 1
i = i + 1
Loop While json_object("categories").Exists(CStr(i))
Else
For Each json_item In json_object("categories")
Sheets(values_sheet).Cells(row, values_category_column) = json_item("name")
row = row + 1
category_count = category_count + 1
Next json_item
End If
'Blank the rest of the category rows
Do While row < row_limit And Len(Cells(row, values_category_column)) > 0
Sheets(values_sheet).Cells(row, values_category_column) = ""
row = row + 1
Loop
End If
'Import severities
If json_object.Exists("severities") Then
row = 2
If TypeName(json_object("severities")) = "Dictionary" Then
i = 0
Do
Sheets(values_sheet).Cells(row, values_sev_column) = json_object("severities")(CStr(i))("name")
row = row + 1
i = i + 1
Loop While json_object("severities").Exists(CStr(i))
Else
For Each json_item In json_object("severities")
Sheets(values_sheet).Cells(row, values_sev_column) = json_item("name")
row = row + 1
Next json_item
End If
'Blank the rest of the severity rows
Do While row < row_limit And Len(Cells(row, values_sev_column)) > 0
Sheets(values_sheet).Cells(row, values_sev_column) = ""
row = row + 1
Loop
End If
MsgBox CStr(item_count) + " check items and " + CStr(category_count) + " categories imported from JSON file " + json_file, vbInformation
Exit Sub
errh:
If Err.Number <> 0 Then
MsgBox "Error while importing checklist from JSON " & Err.Description, vbCritical
End If
End Sub
'Function with error control in case a property does not exist for an object
Function get_object_property(ByVal object_item As Object, property_name As String) As String
On Error GoTo fncerrh
Dim aux As String
aux = object_item(property_name)
'If it is " " or something similar (some translation engines introduce blanks between "&" and "nbsp"), set to null
If Right(aux, 4) = "nbsp" Then aux = ""
get_object_property = aux
Exit Function
fncerrh:
get_object_property = ""
Exit Function
End Function
' Updates a checklist row with the information in the object
Sub update_row(ByVal json_item As Object, ByVal row As Integer, notverified As String)
' Variables and constants
Dim check_category, check_subcategory, check_text, check_description, check_severity, check_status, check_link, check_training, check_graph_success, check_graph_failure, check_guid As String
' Defaults to English "Not Verified"
If Len(notverified) = 0 Then notverified = "Not verified"
' Code
check_category = get_object_property(json_item, "category")
check_subcategory = get_object_property(json_item, "subcategory")
check_text = get_object_property(json_item, "text")
check_description = get_object_property(json_item, "description")
check_severity = get_object_property(json_item, "severity")
check_link = get_object_property(json_item, "link")
check_training = get_object_property(json_item, "training")
check_graph_success = get_object_property(json_item, "graph_success")
check_graph_failure = get_object_property(json_item, "graph_failure")
check_guid = get_object_property(json_item, "guid")
Cells(row, category_column) = check_category
Cells(row, subcategory_column) = check_subcategory
Cells(row, text_column) = check_text
Cells(row, description_column) = check_description
Cells(row, severity_column) = check_severity
Cells(row, guid_column) = check_guid
Cells(row, status_column) = notverified '"notverified" is a variable containing the translation of "not verified"
Cells(row, comments_column) = ""
'Graph queries can optionally be imported or not, since it impacts readability
'Per default, they are only imported when using the English language
If import_graph_queries Then
Cells(row, graph_success_column) = check_graph_success
Cells(row, graph_failure_column) = check_graph_failure
Else
Cells(row, graph_success_column) = ""
Cells(row, graph_failure_column) = ""
End If
'Training and MoreInfo link optional
If Len(check_link) > 0 Then
Cells(row, link_column).Hyperlinks.Add Address:=check_link, TextToDisplay:="More info", Anchor:=Cells(row, link_column), ScreenTip:=check_link
Else
Cells(row, link_column) = ""
End If
If Len(check_training) > 0 Then
Cells(row, training_column).Hyperlinks.Add Address:=check_training, TextToDisplay:="Training", Anchor:=Cells(row, training_column), ScreenTip:=check_training
Else
Cells(row, training_column) = ""
End If
End Sub
'Generates a random GUID
'https://danwagner.co/how-to-generate-a-guid-in-excel-with-vba/
Function generate_guid() As String
On Error GoTo genguiderr
Dim k, h As Variant
generate_guid = Space(36)
For k = 1 To Len(generate_guid)
Randomize
Select Case k
Case 9, 14, 19, 24: h = "-"
Case 15: h = "4"
Case 20: h = Hex(Rnd * 3 + 8)
Case Else: h = Hex(Rnd * 15)
End Select
Mid$(generate_guid, k, 1) = h
Next
generate_guid = LCase$(generate_guid)
genguiderr:
If Err.Number <> 0 Then
MsgBox "Error while generating GUID: " & Err.Description, vbCritical
End If
End Function
'Import Azure Resource Graph query results from a JSON file generated with checklist_graph.sh
Sub import_graph_results()
Dim json_file As Variant
Dim objStream
Dim json As String
Dim json_object, json_item As Object
Dim check_guid, check_success_result, check_failure_result As String
Dim row As Integer
'File pick dialog
ChDir ActiveWorkbook.Path
json_file = Application.GetOpenFilename(Title:="Please choose a file to open", FileFilter:="JSON Files *.json* (*.json),")
If json_file = False Then
MsgBox "No file selected.", vbExclamation, "Action canceled"
Exit Sub
Else
If MsgBox("This action will potentially overwrite existing contents in the Comments column. Do you want to continue?", vbQuestion + vbYesNo) = vbYes Then
'Open and read text file
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "utf-8"
objStream.Open
objStream.LoadFromFile (json_file)
json = objStream.ReadText()
objStream.Close
Set objStream = Nothing
'Remove line breaks and parse
json = Replace(json, vbCrLf, "")
Set json_object = JsonConverter.ParseJson(json) 'This line might give Run-time error 10001 if there are JSON syntax errors
For Each json_item In json_object("checks")
check_guid = get_object_property(json_item, "guid")
check_success_result = get_object_property(json_item, "success")
check_failure_result = get_object_property(json_item, "failure")
'Now find the row with a matching GUID, and populate the comments field
row = row1
Do Until Cells(row, guid_column) = check_guid Or Cells(row, text_column) = ""
row = row + 1
Loop
'And update the comments column
Cells(row, comments_column) = "Compliant resources: " + check_success_result + ". Non-compliant resources: " + check_failure_result
Next json_item
End If
End If
End Sub
' Functions to set global variables when option buttons are pushed
Sub set_japanese()
selected_language = "ja"
import_graph_queries = False
End Sub
Sub set_english()
selected_language = "en"
import_graph_queries = True
End Sub
Sub set_korean()
selected_language = "ko"
import_graph_queries = False
End Sub
Sub set_spanish()
selected_language = "es"
import_graph_queries = False
End Sub
Sub set_portuguese()
selected_language = "pt"
import_graph_queries = False
End Sub
Sub set_aks()
selected_technology = "aks"
End Sub
Sub set_avd()
selected_technology = "avd"
End Sub
Sub set_lz()
selected_technology = "lz"
End Sub
'Delete all from controls, so that the spreadsheet can be saved as macro-free
Sub delete_controls()
Dim item As Object
'Browse all shapes
For Each item In ActiveSheet.Shapes
'Only Form Controls
If item.Type = msoFormControl Then
item.Delete
End If
Next item
End Sub
'Inspect option buttons and set global variables accordingly
Sub set_checklist_variables()
Dim item As Object
'Browse all shapes
For Each item In ActiveSheet.Shapes
'Only Form Controls
If item.Type = msoFormControl Then
'Only option buttons
If Left(item.OLEFormat.Object.Name, 13) = "Option Button" Then
If item.OLEFormat.Object.Value = 1 Then
Select Case item.OLEFormat.Object.Text
Case "AKS"
selected_technology = "aks"
Case "AVD"
selected_technology = "avd"
Case "LZ"
selected_technology = "lz"
Case "English"
selected_language = "en"
import_graph_queries = True
Case "Portuguese"
selected_language = "pt"
import_graph_queries = True
Case "Korean"
selected_language = "ko"
import_graph_queries = True
Case "Japanese"
selected_language = "ja"
import_graph_queries = True
Case "Spanish"
selected_language = "es"
import_graph_queries = True
End Select
End If
End If
End If
Next item
Debug.Print "Selected technology " + selected_technology + ", selected language " + selected_language
End Sub
'Test sub
Sub test()
'If ActiveSheet.Shapes("Option Button 8").Value = True Then
' Debug.Print "Yay!"
'End If
End Sub