summaryrefslogtreecommitdiff
path: root/migrationanalysis/src/driver_docs/sources/CommonMigrationAnalyser.bas
blob: 5fae03a4d399bef00e47fc0a2b1589a71ae34501 (plain)
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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
Attribute VB_Name = "CommonMigrationAnalyser"
'/*************************************************************************
' *
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
' ************************************************************************/

Option Explicit


'***********************************************
'**** APPLICATION COMMON ANALYSIS FUNCTIONS ****
'***********************************************

'** Common - XML Issue and SubIssue strings
'For preparation - need access to some Word/ Excel or PP consts
Public Const CSTR_ISSUE_OBJECTS_GRAPHICS_AND_FRAMES = "ObjectsGraphicsAndFrames"
Public Const CSTR_SUBISSUE_OBJECT_IN_HEADER_FOOTER = "ObjectInHeaderFooter"

Public Const CSTR_ISSUE_INFORMATION = "Information"
Public Const CSTR_ISSUE_CONTENT_DOCUMENT_PROPERTIES = "ContentAndDocumentProperties"
Public Const CSTR_ISSUE_FORMAT = "Format"
Public Const CSTR_ISSUE_PORTABILITY = "Portability"
Public Const CSTR_ISSUE_VBA_MACROS = "VBAMacros"

Public Const CSTR_SUBISSUE_DOCUMENT_PARTS_PROTECTION = "DocumentPartsProtection"
Public Const CSTR_SUBISSUE_EXTERNAL_REFERENCES_IN_MACRO = "ExternalReferencesInMacro"
Public Const CSTR_SUBISSUE_EXTERNAL_REFERENCES_IN_MACRO_COUNT = "ExternalReferencesInMacroCount"
Public Const CSTR_SUBISSUE_GRADIENT = "Gradient"
Public Const CSTR_SUBISSUE_INVALID_PASSWORD_ENTERED = "InvalidPasswordEntered"
Public Const CSTR_SUBISSUE_LINE = "Line"
Public Const CSTR_SUBISSUE_MACRO_PASSWORD_PROTECTION = "PasswordProtected"
Public Const CSTR_SUBISSUE_OLD_WORKBOOK_VERSION = "OldWorkbookVersion"
Public Const CSTR_SUBISSUE_OLE_EMBEDDED = "EmbeddedOLEObject"
Public Const CSTR_SUBISSUE_OLE_LINKED = "LinkedOLEObject"
Public Const CSTR_SUBISSUE_OLE_CONTROL = "OLEControl"
Public Const CSTR_SUBISSUE_OLE_FIELD_LINK = "OLEFieldLink"
Public Const CSTR_SUBISSUE_OLE_UNKNOWN = "UnknownType"
Public Const CSTR_SUBISSUE_PASSWORDS_PROTECTION = "PasswordProtection"
Public Const CSTR_SUBISSUE_PROPERTIES = "Properties"
Public Const CSTR_SUBISSUE_REFERENCES = "References"
Public Const CSTR_SUBISSUE_TRANSPARENCY = "Transparency"
Public Const CSTR_SUBISSUE_VBA_MACROS_NUMLINES = "NumberOfLines"
Public Const CSTR_SUBISSUE_VBA_MACROS_USERFORMS_COUNT = "UserFormsCount"
Public Const CSTR_SUBISSUE_VBA_MACROS_USERFORMS_CONTROL_COUNT = "UserFormsControlCount"
Public Const CSTR_SUBISSUE_VBA_MACROS_USERFORMS_CONTROLTYPE_COUNT = "UserFormsControlTypeCount"
Public Const CSTR_SUBISSUE_VBA_MACROS_UNIQUE_MODULE_COUNT = "UniqueModuleCount"
Public Const CSTR_SUBISSUE_VBA_MACROS_UNIQUE_LINE_COUNT = "UniqueLineCount"
'** END Common - XML Issue and SubIssue strings

'Macro classification bounds
Public Const CMACRO_LINECOUNT_MEDIUM_LBOUND = 50

'Don't localize folder name
Public Const CSTR_COMMON_PREPARATION_FOLDER = "prepared"


Public Enum EnumDocOverallMacroClass
    enMacroNone = 0
    enMacroSimple = 1
    enMacroMedium = 2
    enMacroComplex = 3
End Enum
Public Enum EnumDocOverallIssueClass
    enNone = 0
    enMinor = 1
    enComplex = 2
End Enum

Sub EmptyCollection(docAnalysis As DocumentAnalysis, coll As Collection)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "EmptyCollection"
    Dim Num As Long
    For Num = 1 To coll.count    ' Remove name from the collection.
        coll.Remove 1    ' Default collection numeric indexes
    Next    ' begin at 1.
    Exit Sub
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
End Sub

Public Function Analyze_Macros(docAnalysis As DocumentAnalysis, _
                               userFormTypesDict As Scripting.Dictionary, _
                               currDoc As Object)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_Macros"
    Dim macroDetails As String
    Dim cmpDetails As String
    Dim myProject As VBProject
    Dim myComponent As VBComponent
    Dim numLines As Long
    Dim myIssue As IssueInfo
    Dim wrd As Object
    Dim bUserFormWithEmptyCodeModule As Boolean
     
    On Error Resume Next
    Set myProject = getAppSpecificVBProject(currDoc)
    If Err.Number <> 0 Then
        ' Failed to get access to VBProject
        WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & _
            RID_STR_COMMON_ATTRIBUTE_UNABLE_TO_ACCESS_VBPROJECT & ":" & _
            RID_STR_COMMON_ATTRIBUTE_FURTHER_MACRO_ANALYSIS_NOT_POSSIBLE
        
        GoTo FinalExit
    End If
    
    On Error GoTo HandleErrors
    If myProject.Protection = vbext_pp_locked Then
        Set myIssue = New IssueInfo
        With myIssue
            .IssueID = CID_VBA_MACROS
            .IssueType = RID_STR_COMMON_ISSUE_VBA_MACROS
            .SubType = RID_STR_COMMON_SUBISSUE_MACRO_PASSWORD_PROTECTION
            .Location = .CLocationDocument
            
            .IssueTypeXML = CSTR_ISSUE_VBA_MACROS
            .SubTypeXML = CSTR_SUBISSUE_MACRO_PASSWORD_PROTECTION
            .locationXML = .CXMLLocationDocument
            
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_VBPROJECT_PASSWORD
            .Values.Add RID_STR_COMMON_ATTRIBUTE_FURTHER_MACRO_ANALYSIS_NOT_POSSIBLE
        End With
        docAnalysis.IssuesCountArray(CID_VBA_MACROS) = _
            docAnalysis.IssuesCountArray(CID_VBA_MACROS) + 1
        docAnalysis.Issues.Add myIssue
        docAnalysis.MacroIssuesCount = docAnalysis.MacroIssuesCount + 1
        
        docAnalysis.HasMacros = True
        GoTo FinalExit
    End If

    Dim myContolDict As Scripting.Dictionary
    For Each myComponent In myProject.VBComponents
    
        bUserFormWithEmptyCodeModule = False
        If CheckEmptyProject(docAnalysis, myProject, myComponent) Then
            If myComponent.Type <> vbext_ct_MSForm Then
                GoTo FOREACH_CONTINUE
            Else
                bUserFormWithEmptyCodeModule = True
            End If
        End If
        
        Analyze_MacrosForPortabilityIssues docAnalysis, myProject, myComponent
        
        Set myIssue = New IssueInfo
        With myIssue
            .IssueID = CID_VBA_MACROS
            .IssueType = RID_STR_COMMON_ISSUE_VBA_MACROS
            .SubType = RID_STR_COMMON_SUBISSUE_PROPERTIES
            .Location = .CLocationDocument
            
            .IssueTypeXML = CSTR_ISSUE_VBA_MACROS
            .SubTypeXML = CSTR_SUBISSUE_PROPERTIES
            .locationXML = .CXMLLocationDocument
            
            .SubLocation = VBComponentType(myComponent)
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_PROJECT
            .Values.Add myProject.name
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_COMPONENT
            .Values.Add myComponent.name
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_PROCEDURES
            .Values.Add VBNumFuncs(docAnalysis, myComponent.CodeModule), RID_STR_COMMON_ATTRIBUTE_PROCEDURES
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NUMBER_OF_LINES
            numLines = VBNumLines(docAnalysis, myComponent.CodeModule)
            .Values.Add numLines, RID_STR_COMMON_ATTRIBUTE_NUMBER_OF_LINES
            
            If bUserFormWithEmptyCodeModule Then
                .Attributes.Add RID_STR_COMMON_ATTRIBUTE_SIGNATURE
                .Values.Add RID_STR_COMMON_NA, RID_STR_COMMON_ATTRIBUTE_SIGNATURE
            Else
                .Attributes.Add RID_STR_COMMON_ATTRIBUTE_SIGNATURE
                .Values.Add MD5HashString( _
                    myComponent.CodeModule.Lines(1, myComponent.CodeModule.CountOfLines)), _
                    RID_STR_COMMON_ATTRIBUTE_SIGNATURE
            End If
            
            docAnalysis.MacroTotalNumLines = numLines + docAnalysis.MacroTotalNumLines
        End With
        
        ' User Forms - control details
        If (myComponent.Type = vbext_ct_MSForm) And Not bUserFormWithEmptyCodeModule Then
            myIssue.Attributes.Add RID_STR_COMMON_ATTRIBUTE_CONTROLS
            myIssue.Values.Add myComponent.Designer.Controls.count, RID_STR_COMMON_ATTRIBUTE_CONTROLS
            docAnalysis.MacroNumUserForms = 1 + docAnalysis.MacroNumUserForms
            docAnalysis.MacroNumUserFormControls = myComponent.Designer.Controls.count + docAnalysis.MacroNumUserFormControls
            
            Dim myControl As Control
            Dim controlTypes As String
            Dim myType As String
            
            Set myContolDict = New Scripting.Dictionary
            
            For Each myControl In myComponent.Designer.Controls
                myType = TypeName(myControl)
                If myContolDict.Exists(myType) Then
                   myContolDict.item(myType) = myContolDict.item(myType) + 1
                Else
                   myContolDict.Add myType, 1
                End If
                If userFormTypesDict.Exists(myType) Then
                   userFormTypesDict.item(myType) = userFormTypesDict.item(myType) + 1
                Else
                   userFormTypesDict.Add myType, 1
                End If
            Next
            
            If myComponent.Designer.Controls.count > 0 Then
                Dim count As Long
                Dim vKeyArray As Variant
                Dim vItemArray As Variant
                
                vKeyArray = myContolDict.Keys
                vItemArray = myContolDict.Items
                
                controlTypes = ""
                For count = 0 To myContolDict.count - 1
                    controlTypes = controlTypes & vKeyArray(count) & " " & CInt(vItemArray(count)) & " "
                Next count
                myIssue.Attributes.Add RID_STR_COMMON_ATTRIBUTE_USERFORM_TYPE
                myIssue.Values.Add controlTypes, RID_STR_COMMON_ATTRIBUTE_USERFORM_TYPE
                
                myIssue.Attributes.Add RID_STR_COMMON_ATTRIBUTE_USERFORM_TYPES_COUNT
                myIssue.Values.Add myContolDict.count, RID_STR_COMMON_ATTRIBUTE_USERFORM_TYPES_COUNT
            
                docAnalysis.MacroNumUserFormControlTypes = myContolDict.count + docAnalysis.MacroNumUserFormControlTypes
            End If
            Set myContolDict = Nothing
        End If
        
        'Check for occurence of " Me " in Form and Class Modules
        If myComponent.Type = vbext_ct_MSForm Or _
            myComponent.Type = vbext_ct_ClassModule Then
         
            Dim strFind As String
            strFind = ""
            count = 0
            strFind = VBFindLines(docAnalysis, myComponent.CodeModule, "Me", count, bWholeWord:=True)
'            If (strFind <> "") Then MsgBox strFind

            If count > 0 Then
                myIssue.Attributes.Add RID_STR_COMMON_ATTRIBUTE_CLASS_ME_COUNT
                myIssue.Values.Add count, RID_STR_COMMON_ATTRIBUTE_CLASS_ME_COUNT
            End If
        End If
        
        docAnalysis.IssuesCountArray(CID_VBA_MACROS) = _
            docAnalysis.IssuesCountArray(CID_VBA_MACROS) + 1
        docAnalysis.Issues.Add myIssue
        docAnalysis.MacroIssuesCount = docAnalysis.MacroIssuesCount + 1
        
        Set myIssue = Nothing
        
FOREACH_CONTINUE:
        'No equiv to C continue in VB
    Next myComponent 'End - For Each myComponent
    
    If docAnalysis.IssuesCountArray(CID_VBA_MACROS) > 0 Then
        Analyze_VBEReferences docAnalysis, currDoc
        docAnalysis.HasMacros = True
    End If
    
FinalExit:
    docAnalysis.MacroOverallClass = ClassifyDocOverallMacroClass(docAnalysis)
    
    Set myProject = Nothing
    Set myIssue = Nothing
    Set myContolDict = Nothing
    Exit Function
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Function

Function CheckOnlyEmptyProject(docAnalysis As DocumentAnalysis, currDoc As Object) As Boolean
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "CheckOnlyEmptyProject"
    Dim myProject As VBProject
    Set myProject = getAppSpecificVBProject(currDoc)
    Dim myVBComponent As VBComponent

    For Each myVBComponent In myProject.VBComponents
        If Not CheckEmptyProject(docAnalysis, myProject, myVBComponent) Then
            CheckOnlyEmptyProject = False
            GoTo FinalExit
        End If
    Next myVBComponent
    
    CheckOnlyEmptyProject = True

FinalExit:
    Set myProject = Nothing
    Exit Function
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Function

Sub Analyze_VBEReferences(docAnalysis As DocumentAnalysis, currDoc As Object)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_VBEReferences"
    'References
    Dim Ref As Reference
    Dim fso As Scripting.FileSystemObject
    Dim myVBProject As VBProject
    Dim myVBComponent As VBComponent
    
    Set fso = New Scripting.FileSystemObject
    
    If CheckOnlyEmptyProject(docAnalysis, currDoc) Then
        Exit Sub
    End If
    Set myVBProject = getAppSpecificVBProject(currDoc)
    
    For Each Ref In myVBProject.References
        Analyze_VBEReferenceSingle docAnalysis, Ref, fso
    Next Ref
    
FinalExit:
    Set myVBProject = Nothing
    Set fso = Nothing
    Exit Sub
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_VBEReferenceSingle(docAnalysis As DocumentAnalysis, Ref As Reference, fso As Scripting.FileSystemObject)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_VBEReferenceSingle"
    'References
    Dim myIssue As IssueInfo
    Dim bBadRef As Boolean
    
    Set myIssue = New IssueInfo
    With myIssue
        .IssueID = CID_INFORMATION_REFS
        .IssueType = RID_STR_COMMON_ISSUE_INFORMATION
        .SubType = RID_STR_COMMON_SUBISSUE_REFERENCES
        .Location = .CLocationDocument
            
        .IssueTypeXML = CSTR_ISSUE_INFORMATION
        .SubTypeXML = CSTR_SUBISSUE_REFERENCES
        .locationXML = .CXMLLocationDocument
            
        If Ref.GUID = "" Then
            bBadRef = True
        Else
            bBadRef = False
        End If
        If Not bBadRef Then
            .SubLocation = LCase(fso.GetFileName(Ref.FullPath))
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add Ref.name, RID_STR_COMMON_ATTRIBUTE_NAME
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_DESCRIPTION
            .Values.Add Ref.Description, RID_STR_COMMON_ATTRIBUTE_DESCRIPTION
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_FILE
            .Values.Add LCase(fso.GetFileName(Ref.FullPath)), RID_STR_COMMON_ATTRIBUTE_FILE
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_PATH
            .Values.Add LCase(Ref.FullPath), RID_STR_COMMON_ATTRIBUTE_PATH
        Else
            .SubLocation = RID_STR_COMMON_NA
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add RID_STR_COMMON_ATTRIBUTE_MISSING, RID_STR_COMMON_ATTRIBUTE_NAME
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_DESCRIPTION
            .Values.Add RID_STR_COMMON_ATTRIBUTE_CHECK_DOCUMENT_REFERENCES, RID_STR_COMMON_ATTRIBUTE_DESCRIPTION
        End If

        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_MAJOR
        .Values.Add IIf(Not bBadRef, Ref.Major, ""), RID_STR_COMMON_ATTRIBUTE_MAJOR
        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_MINOR
        .Values.Add IIf(Not bBadRef, Ref.Minor, ""), RID_STR_COMMON_ATTRIBUTE_MINOR
        
        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_TYPE
        .Values.Add IIf(Ref.Type = vbext_rk_Project, RID_STR_COMMON_ATTRIBUTE_PROJECT, RID_STR_COMMON_ATTRIBUTE_TYPELIB), RID_STR_COMMON_ATTRIBUTE_TYPE
    
        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_BUILTIN
        .Values.Add IIf(Ref.BuiltIn, RID_STR_COMMON_ATTRIBUTE_BUILTIN, RID_STR_COMMON_ATTRIBUTE_CUSTOM), RID_STR_COMMON_ATTRIBUTE_BUILTIN
        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_ISBROKEN
        .Values.Add IIf(bBadRef, RID_STR_COMMON_ATTRIBUTE_BROKEN, RID_STR_COMMON_ATTRIBUTE_INTACT), RID_STR_COMMON_ATTRIBUTE_ISBROKEN
        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_GUID
        .Values.Add IIf(Ref.Type = vbext_rk_TypeLib, Ref.GUID, ""), RID_STR_COMMON_ATTRIBUTE_GUID
    End With
    
    docAnalysis.References.Add myIssue
     
FinalExit:
    Set myIssue = Nothing
    Exit Sub
    
HandleErrors:
    WriteDebugLevelTwo currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_MacrosForPortabilityIssues(docAnalysis As DocumentAnalysis, myProject As VBProject, myComponent As VBComponent)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_MacrosForPortabilityIssues"
    Dim myIssue As IssueInfo
    Dim count As Long
    
    ' Code Modules
    Dim strFind As String
    strFind = VBFindLines(docAnalysis, myComponent.CodeModule, "CreateObject", count, bWholeWord:=True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "GetObject", count, bWholeWord:=True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "ADODB.", count, True, True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "Word.", count, True, True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "Excel.", count, True, True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "PowerPoint.", count, True, True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "Access.", count, True, True) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "Declare Function ", count, False) & _
        VBFindLines(docAnalysis, myComponent.CodeModule, "Declare Sub ", count, False)

    
    If (strFind <> "") And (myComponent.Type <> vbext_ct_Document) Then
        Set myIssue = New IssueInfo
        With myIssue
            .IssueID = CID_PORTABILITY
            .IssueType = RID_STR_COMMON_ISSUE_PORTABILITY
            .SubType = RID_STR_COMMON_SUBISSUE_EXTERNAL_REFERENCES_IN_MACROS
            .Location = .CLocationDocument

            .IssueTypeXML = CSTR_ISSUE_PORTABILITY
            .SubTypeXML = CSTR_SUBISSUE_EXTERNAL_REFERENCES_IN_MACRO
            .locationXML = .CXMLLocationDocument

            .SubLocation = VBComponentType(myComponent)

            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_PROJECT
            .Values.Add myProject.name
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_COMPONENT
            .Values.Add myComponent.name
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NON_PORTABLE_EXTERNAL_REFERENCES
            .Values.Add RID_STR_COMMON_ATTRIBUTE_INCLUDING & vbLf & Left(strFind, Len(strFind) - 1)
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NON_PORTABLE_EXTERNAL_REFERENCES_COUNT
            .Values.Add count, RID_STR_COMMON_ATTRIBUTE_NON_PORTABLE_EXTERNAL_REFERENCES_COUNT
        End With
        docAnalysis.IssuesCountArray(CID_PORTABILITY) = _
            docAnalysis.IssuesCountArray(CID_PORTABILITY) + 1
        docAnalysis.Issues.Add myIssue
        docAnalysis.MacroNumExternalRefs = count + docAnalysis.MacroNumExternalRefs
        docAnalysis.MacroIssuesCount = docAnalysis.MacroIssuesCount + 1
    End If
    
FinalExit:
    Set myIssue = Nothing
    Exit Sub
    
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
Resume FinalExit
End Sub

'Find Lines in  code module containing strFind and return list of them
Function VBFindLines(docAnalysis As DocumentAnalysis, vbcm As CodeModule, strFind As String, _
    count As Long, _
    Optional bInProcedure As Boolean = True, _
    Optional bUsingNew As Boolean = False, _
    Optional bWholeWord As Boolean = False, _
    Optional bMatchCase As Boolean = False) As String
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "VBFindLines"
    Dim lngStartLine As Long
    Dim lngStartCol As Long
    Dim lngEndLine As Long
    Dim lngEndCol As Long
    Dim strLine As String
    lngStartLine = 1
    lngStartCol = 1
    lngEndLine = vbcm.CountOfLines
    Dim tmpString As String
    If (vbcm.CountOfLines = 0) Then
        Exit Function
    End If
    tmpString = vbcm.Lines(vbcm.CountOfLines, 1)
    lngEndCol = Len(vbcm.Lines(vbcm.CountOfLines, 1))
    Dim lngType As Long
    Dim strProc As String
    Dim retStr As String
        
    ' Search
    Do While vbcm.Find(strFind, lngStartLine, _
        lngStartCol, lngEndLine, lngEndCol, bWholeWord, bMatchCase)
        
        'Ignore any lines using this func
        If InStr(1, vbcm.Lines(lngStartLine, 1), "VBFindLines") <> 0 Then
            GoTo CONTINUE_LOOP
        End If
        
        If bInProcedure Then
            If bUsingNew Then
                If InStr(1, vbcm.Lines(lngStartLine, 1), "New") <> 0 Then
                    strProc = vbcm.ProcOfLine(lngStartLine, lngType)
                Else
                    strProc = ""
                End If
            Else
                strProc = vbcm.ProcOfLine(lngStartLine, lngType)
            End If
            If strProc = "" Then GoTo CONTINUE_LOOP
            
            VBFindLines = VBFindLines & "[" & strProc & " ( ) - " & lngStartLine & " ]" & _
                vbLf & vbcm.Lines(lngStartLine, 1) & vbLf
        Else
            strProc = vbcm.Lines(lngStartLine, 1)
            If strProc = "" Then GoTo CONTINUE_LOOP
            
            'Can be External refs, Const, Type or variable declarations
            If InStr(1, vbcm.Lines(lngStartLine, 1), "Declare Function") <> 0 Then
            VBFindLines = VBFindLines & "[" & RID_STR_COMMON_DEC_TO_EXTERNAL_LIBRARY & " - " & lngStartLine & " ]" & _
                vbLf & strProc & vbLf
            Else
                VBFindLines = VBFindLines & "[" & RID_STR_COMMON_VB_COMPONENT_MODULE & " " & strFind & _
                    " - " & lngStartLine & " ]" & vbLf
            End If
        End If
        count = count + 1
        
CONTINUE_LOOP:
        'Reset Params to search for next hit
        lngStartLine = lngEndLine + 1
        lngStartCol = 1
        lngEndLine = vbcm.CountOfLines
        lngEndCol = Len(vbcm.Lines(vbcm.CountOfLines, 1))
        
        If lngStartLine >= lngEndLine Then Exit Function
        
    Loop 'End - Do While vbcm.Find
    VBFindLines = VBFindLines
    Exit Function
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
End Function
Function VBNumLines(docAnalysis As DocumentAnalysis, vbcm As CodeModule) As Long
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "VBNumLines"
    Dim cLines As Long
    Dim lngType As Long
    Dim strProc As String
    
    'Issue: Just give line count in module to be in sync with Macro Analysis and Migration Wizard
    VBNumLines = vbcm.CountOfLines
    
    'For cLines = 1 To vbcm.CountOfLines
    '    strProc = vbcm.ProcOfLine(cLines, lngType)
    '    If strProc <> "" Then
    '        VBNumLines = VBNumLines - _
    '            (vbcm.ProcBodyLine(strProc, lngType) - vbcm.ProcStartLine(strProc, lngType))
    '        cLines = cLines + vbcm.ProcCountLines(strProc, lngType) - 1
    '    End If
    'Next
    Exit Function
    
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
End Function
Function VBNumFuncs(docAnalysis As DocumentAnalysis, vbcm As CodeModule) As Long
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "VBNumFuncs"
    Dim cLines As Long
    Dim lngType As Long
    Dim strProc As String
    
    For cLines = 1 To vbcm.CountOfLines
        strProc = vbcm.ProcOfLine(cLines, lngType)
        If strProc <> "" Then
            VBNumFuncs = VBNumFuncs + 1
            cLines = cLines + vbcm.ProcCountLines(strProc, lngType) - 1
        End If
    Next
    Exit Function
HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
End Function

Function VBComponentType(vbc As VBComponent) As String
    Select Case vbc.Type
        Case vbext_ct_StdModule
            VBComponentType = RID_STR_COMMON_VB_COMPONENT_STANDARD
        Case vbext_ct_ClassModule
            VBComponentType = RID_STR_COMMON_VB_COMPONENT_CLASS
        Case vbext_ct_MSForm
            VBComponentType = RID_STR_COMMON_VB_COMPONENT_USER_FORM
        Case vbext_ct_Document
            VBComponentType = RID_STR_COMMON_VB_COMPONENT_DOCUMENT
        Case 11 'vbext_ct_ActiveX Designer
            VBComponentType = RID_STR_COMMON_VB_COMPONENT_ACTIVEX_DESIGNER
        Case Else
            VBComponentType = RID_STR_COMMON_UNKNOWN
    End Select
End Function

Function CheckEmptyProject(docAnalysis As DocumentAnalysis, myProject As VBProject, myComponent As VBComponent) As Boolean
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "CheckEmptyProject"
    Dim bEmptyProject As Boolean
    
    'Bug: Can have empty project with different name from default, would be picked up
    ' as not empty.
    'bEmptyProject = _
    '        (StrComp(myProject.name, CTOPLEVEL_PROJECT) = 0) And _
    '        (VBNumFuncs(docAnalysis, myComponent.CodeModule) = 0) And _
    '        (VBNumLines(docAnalysis, myComponent.CodeModule) < 3)
    
    ' Code Modules
    Dim strFind As String
    Dim count As Long
    'Check for:
    'Public Const myFoo ....
    'Public Declare Function ....
    'Public myVar As ...
    strFind = VBFindLines(docAnalysis, myComponent.CodeModule, "Public", _
        count, bInProcedure:=False, bWholeWord:=True, bMatchCase:=True)
        
    bEmptyProject = _
            (VBNumFuncs(docAnalysis, myComponent.CodeModule) = 0) And _
            (VBNumLines(docAnalysis, myComponent.CodeModule) < 3) And _
            (strFind = "")
            
    CheckEmptyProject = IIf(bEmptyProject, True, False)
    Exit Function


HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
End Function

Function getCustomDocPropTypeAsString(propType As MsoDocProperties)
    Dim Str As String

    Select Case propType
    Case msoPropertyTypeBoolean
        Str = RID_STR_COMMON_YES_OR_NO
    Case msoPropertyTypeDate
        Str = RID_STR_COMMON_DATE
    Case msoPropertyTypeFloat
        Str = RID_STR_COMMON_NUMBER
    Case msoPropertyTypeNumber
        Str = RID_STR_COMMON_NUMBER
    Case msoPropertyTypeString
        Str = RID_STR_COMMON_TEXT
    Case Else
        Str = "Unknown"
    End Select
    
    getCustomDocPropTypeAsString = Str
End Function

Sub HandleProtectedDocInvalidPassword(docAnalysis As DocumentAnalysis, strError As String, fso As FileSystemObject)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "HandleProtectedDocInvalidPassword"
    Dim f As File
    Set f = fso.GetFile(docAnalysis.name)

    docAnalysis.Application = RID_STR_COMMON_PASSWORD_SKIPDOC

    On Error Resume Next
    docAnalysis.PageCount = 0
    docAnalysis.Created = f.DateCreated
    docAnalysis.Modified = f.DateLastModified
    docAnalysis.Accessed = f.DateLastAccessed
    docAnalysis.Printed = DateValue("01/01/1900")
    docAnalysis.SavedBy = RID_STR_COMMON_NA
    docAnalysis.Revision = 0
    docAnalysis.Template = RID_STR_COMMON_NA
    On Error GoTo HandleErrors

    Dim myIssue As IssueInfo
    Set myIssue = New IssueInfo

    With myIssue
        .IssueID = CID_CONTENT_AND_DOCUMENT_PROPERTIES
        .IssueType = RID_STR_COMMON_ISSUE_CONTENT_AND_DOCUMENT_PROPERTIES
        .SubType = RID_STR_COMMON_SUBISSUE_INVALID_PASSWORD_ENTERED
        .Location = .CLocationDocument

        .IssueTypeXML = CSTR_ISSUE_CONTENT_DOCUMENT_PROPERTIES
        .SubTypeXML = CSTR_SUBISSUE_INVALID_PASSWORD_ENTERED
        .locationXML = .CXMLLocationDocument

        .Attributes.Add RID_STR_COMMON_ATTRIBUTE_PASSWORD
        .Values.Add strError

        docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) = _
                docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) + 1
    End With

    docAnalysis.Issues.Add myIssue

FinalExit:
    Set myIssue = Nothing
    Set f = Nothing
    Exit Sub

HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_OLEEmbeddedSingleShape(docAnalysis As DocumentAnalysis, aShape As Shape, mySubLocation As Variant)

    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_OLEEmbeddedSingleShape"
    Dim myIssue As IssueInfo
    Dim bOleObject As Boolean
    Dim TypeAsString As String
    Dim XMLTypeAsString As String
    Dim objName As String
    
    bOleObject = (aShape.Type = msoEmbeddedOLEObject) Or _
                    (aShape.Type = msoLinkedOLEObject) Or _
                    (aShape.Type = msoOLEControlObject)
                    
    If Not bOleObject Then Exit Sub
            
    aShape.Select
    Select Case aShape.Type
        Case msoEmbeddedOLEObject
            TypeAsString = RID_STR_COMMON_OLE_EMBEDDED
            XMLTypeAsString = CSTR_SUBISSUE_OLE_EMBEDDED
        Case msoLinkedOLEObject
            TypeAsString = RID_STR_COMMON_OLE_LINKED
            XMLTypeAsString = CSTR_SUBISSUE_OLE_LINKED
        Case msoOLEControlObject
            TypeAsString = RID_STR_COMMON_OLE_CONTROL
            XMLTypeAsString = CSTR_SUBISSUE_OLE_CONTROL
        Case Else
            TypeAsString = RID_STR_COMMON_OLE_UNKNOWN
            XMLTypeAsString = CSTR_SUBISSUE_OLE_UNKNOWN
    End Select
    
    Dim appStr As String
    appStr = getAppSpecificApplicationName
        
    Set myIssue = New IssueInfo
    With myIssue
        .IssueID = CID_PORTABILITY
        .IssueType = RID_STR_COMMON_ISSUE_PORTABILITY
        .SubType = TypeAsString
        .Location = .CLocationPage
        .SubLocation = mySubLocation
        
        .IssueTypeXML = CSTR_ISSUE_PORTABILITY
        .SubTypeXML = XMLTypeAsString
        .locationXML = .CXMLLocationPage
        
        .Line = aShape.top
        .column = aShape.Left

        If aShape.name <> "" Then
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add aShape.name
        End If
        
        If aShape.Type = msoEmbeddedOLEObject Or _
           aShape.Type = msoOLEControlObject Then
            Dim objType As String
            On Error Resume Next
            
            objType = getAppSpecificOLEClassType(aShape)
            
            If objType = "" Then GoTo FinalExit
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_OBJECT_TYPE
            .Values.Add objType
                        
            If aShape.Type = msoOLEControlObject Then
                docAnalysis.MacroNumOLEControls = 1 + docAnalysis.MacroNumOLEControls
            End If
            
            If appStr = CAPPNAME_POWERPOINT Then
            '#114127: Too many open windows
            'Checking for OLEFormat.Object is Nothing or IsEmpty still causes problem
                If objType <> "Equation.3" Then
                    objName = aShape.OLEFormat.Object.name
                    If Err.Number = 0 Then
                        If aShape.name <> objName Then
                            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_OBJECT_NAME
                            .Values.Add objName
                       End If
                    End If
                End If
            Else
                If Not (aShape.OLEFormat.Object) Is Nothing Then
                    objName = aShape.OLEFormat.Object.name
                    If Err.Number = 0 Then
                        If aShape.name <> objName Then
                            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_OBJECT_NAME
                            .Values.Add objName
                        End If
                    End If
                End If
            End If
            
            On Error GoTo HandleErrors
        End If
        
        If aShape.Type = msoLinkedOLEObject Then
            If appStr <> CAPPNAME_WORD Then
                On Error Resume Next
                Dim path As String
                path = aShape.OLEFormat.Object.SourceFullName
                If Err.Number = 0 Then
                    .Attributes.Add RID_STR_COMMON_ATTRIBUTE_SOURCE
                    .Values.Add path
                End If
                On Error GoTo HandleErrors
            Else
                .Attributes.Add RID_STR_COMMON_ATTRIBUTE_SOURCE
                .Values.Add aShape.LinkFormat.SourceFullName
            End If
        End If
        
        docAnalysis.IssuesCountArray(CID_PORTABILITY) = _
            docAnalysis.IssuesCountArray(CID_PORTABILITY) + 1
    End With
    docAnalysis.Issues.Add myIssue
            
FinalExit:
    Set myIssue = Nothing
    Exit Sub
     
HandleErrors:
    WriteDebugLevelTwo currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_Lines(docAnalysis As DocumentAnalysis, myShape As Shape, mySubLocation As Variant)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_Lines"

    If myShape.Line.Style = msoLineSingle Or _
       myShape.Line.Style = msoLineStyleMixed Then Exit Sub

    Dim myIssue As IssueInfo
    Set myIssue = New IssueInfo

    With myIssue
        .IssueID = CID_CONTENT_AND_DOCUMENT_PROPERTIES
        .IssueType = RID_STR_COMMON_ISSUE_CONTENT_AND_DOCUMENT_PROPERTIES
        .SubType = RID_RESXLS_COST_LineStyle
        .Location = .CLocationPage
        .SubLocation = mySubLocation
        
        .IssueTypeXML = CSTR_ISSUE_CONTENT_DOCUMENT_PROPERTIES
        .SubTypeXML = CSTR_SUBISSUE_LINE
        .locationXML = .CXMLLocationPage
        
        .Line = myShape.top
        .column = myShape.Left

        If myShape.name <> "" Then
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add myShape.name
        End If

        AddIssueDetailsNote myIssue, 0, RID_STR_COMMON_SUBISSUE_LINE_NOTE

        docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) = _
                docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) + 1
    End With
       
    docAnalysis.Issues.Add myIssue
    
FinalExit:
    Set myIssue = Nothing
    Exit Sub

HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_Transparency(docAnalysis As DocumentAnalysis, myShape As Shape, mySubLocation As Variant)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_Transparency"

    If Not myShape.Type = msoPicture Then Exit Sub

    Dim bHasTransparentBkg
    bHasTransparentBkg = False

    On Error Resume Next
    If myShape.PictureFormat.TransparentBackground = msoTrue Then
        If Error.Number = 0 Then
            bHasTransparentBkg = True
        End If
    End If
    
    On Error GoTo HandleErrors
    If Not bHasTransparentBkg Then Exit Sub

    Dim myIssue As IssueInfo
    Set myIssue = New IssueInfo
    
    With myIssue
        .IssueID = CID_CONTENT_AND_DOCUMENT_PROPERTIES
        .IssueType = RID_STR_COMMON_ISSUE_CONTENT_AND_DOCUMENT_PROPERTIES
        .SubType = RID_RESXLS_COST_Transparent
        .Location = .CLocationSlide
        .SubLocation = mySubLocation
        
        .IssueTypeXML = CSTR_ISSUE_CONTENT_DOCUMENT_PROPERTIES
        .SubTypeXML = CSTR_SUBISSUE_TRANSPARENCY
        .locationXML = .CXMLLocationPage
        
        .Line = myShape.top
        .column = myShape.Left

        If myShape.name <> "" Then
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add myShape.name
        End If

        AddIssueDetailsNote myIssue, 0, RID_STR_COMMON_SUBISSUE_TRANSPARENCY_NOTE

        docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) = _
                docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) + 1
    End With
       
    docAnalysis.Issues.Add myIssue
    
FinalExit:
    Set myIssue = Nothing
    Exit Sub

HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Sub Analyze_Gradients(docAnalysis As DocumentAnalysis, myShape As Shape, mySubLocation As Variant)
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "Analyze_Gradients"

    If myShape.Fill.Type <> msoFillGradient Then Exit Sub
    
    Dim bUsesPresetGradient, bUsesFromCorner, bUsesFromCenter
    bUsesPresetGradient = False
    bUsesFromCorner = False
    bUsesFromCenter = False

    On Error Resume Next
    If myShape.Fill.PresetGradientType <> msoPresetGradientMixed Then
        If Error.Number = 0 Then
            bUsesPresetGradient = True
        End If
    End If
    If myShape.Fill.GradientStyle <> msoGradientFromCorner Then
        If Error.Number = 0 Then
            bUsesFromCorner = True
        End If
    End If
    If myShape.Fill.GradientStyle <> msoGradientFromCenter Then
        If Error.Number = 0 Then
            bUsesFromCenter = True
        End If
    End If
    
    On Error GoTo HandleErrors
    If Not bUsesPresetGradient And Not bUsesFromCorner _
       And Not bUsesFromCenter Then Exit Sub

    Dim myIssue As IssueInfo
    Set myIssue = New IssueInfo
    
    With myIssue
        .IssueID = CID_CONTENT_AND_DOCUMENT_PROPERTIES
        .IssueType = RID_STR_COMMON_ISSUE_CONTENT_AND_DOCUMENT_PROPERTIES
        .SubType = RID_RESXLS_COST_GradientStyle
        .Location = .CLocationSlide
        .SubLocation = mySubLocation
        
        .IssueTypeXML = CSTR_ISSUE_CONTENT_DOCUMENT_PROPERTIES
        .SubTypeXML = CSTR_SUBISSUE_GRADIENT
        .locationXML = .CXMLLocationSlide
        
        .Line = myShape.top
        .column = myShape.Left

        If myShape.name <> "" Then
            .Attributes.Add RID_STR_COMMON_ATTRIBUTE_NAME
            .Values.Add myShape.name
        End If

        If bUsesPresetGradient Then
            AddIssueDetailsNote myIssue, 0, RID_STR_COMMON_SUBISSUE_GRADIENT_PRESET_NOTE
        ElseIf bUsesFromCorner Then
            AddIssueDetailsNote myIssue, 0, RID_STR_COMMON_SUBISSUE_GRADIENT_CORNER_NOTE
        Else
            AddIssueDetailsNote myIssue, 0, RID_STR_COMMON_SUBISSUE_GRADIENT_CENTER_NOTE
        End If

        docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) = _
                docAnalysis.IssuesCountArray(CID_CONTENT_AND_DOCUMENT_PROPERTIES) + 1
    End With
       
    docAnalysis.Issues.Add myIssue
    
FinalExit:
    Set myIssue = Nothing
    Exit Sub

HandleErrors:
    WriteDebug currentFunctionName & " : " & docAnalysis.name & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Sub

Private Function CreateFullPath(newPath As String, fso As FileSystemObject)
    'We don't want to create 'c:\'
    If (Len(newPath) < 4) Then
        Exit Function
    End If

    'Create parent folder first
    If (Not fso.FolderExists(fso.GetParentFolderName(newPath))) Then
        CreateFullPath fso.GetParentFolderName(newPath), fso
    End If

    If (Not fso.FolderExists(newPath)) Then
        fso.CreateFolder (newPath)
    End If
End Function

Function GetPreparedFullPath(sourceDocPath As String, startDir As String, storeToDir As String, _
    fso As FileSystemObject) As String
    On Error GoTo HandleErrors
    Dim currentFunctionName As String
    currentFunctionName = "GetPreparedFullPath"
    GetPreparedFullPath = ""

    Dim preparedPath As String
        
    preparedPath = Right(sourceDocPath, Len(sourceDocPath) - Len(startDir))
    If Left(preparedPath, 1) = "\" Then
        preparedPath = Right(preparedPath, Len(preparedPath) - 1)
    End If
    
    'Allow for root folder C:\
    If Right(storeToDir, 1) <> "\" Then
        preparedPath = storeToDir & "\" & CSTR_COMMON_PREPARATION_FOLDER & "\" & preparedPath
    Else
        preparedPath = storeToDir & CSTR_COMMON_PREPARATION_FOLDER & "\" & preparedPath
    End If
    
    'Debug: MsgBox "Preppath: " & preparedPath
    CreateFullPath fso.GetParentFolderName(preparedPath), fso

    'Only set if folder to save to exists or has been created, otherwise return ""
    GetPreparedFullPath = preparedPath
    
FinalExit:
    Exit Function
     
HandleErrors:
    WriteDebugLevelTwo currentFunctionName & " : " & sourceDocPath & ": " & Err.Number & " " & Err.Description & " " & Err.Source
    Resume FinalExit
End Function

Function ClassifyDocOverallMacroClass(docAnalysis As DocumentAnalysis) As EnumDocOverallMacroClass
    ClassifyDocOverallMacroClass = enMacroNone
    
    If Not docAnalysis.HasMacros Then Exit Function
    
    If (docAnalysis.MacroTotalNumLines >= CMACRO_LINECOUNT_MEDIUM_LBOUND) Then
        If (docAnalysis.MacroNumExternalRefs > 0) Or _
            (docAnalysis.MacroNumOLEControls > 0 Or docAnalysis.MacroNumFieldsUsingMacros > 0) Or _
            docAnalysis.MacroNumUserForms > 0 Then
            ClassifyDocOverallMacroClass = enMacroComplex
        Else
            ClassifyDocOverallMacroClass = enMacroMedium
        End If
    Else
        ClassifyDocOverallMacroClass = enMacroSimple
    End If
    
End Function