-
Notifications
You must be signed in to change notification settings - Fork 0
/
scholar-search.txt
executable file
·2262 lines (1832 loc) · 61.9 KB
/
scholar-search.txt
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
'ssf-begin
';
'workbook
' name;scholar-search.xlsm/F3XScholarSearch
'book-identity
' title;Scholar Search
' description;Web search helper for books and papers
'require
' ;{0D452EE1-E08F-101A-852E-02608C4D0BB4} 2 0 Microsoft Forms 2.0 Object Library
' ;{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} 1 1 Microsoft Internet Controls
' ;{00000205-0000-0010-8000-00AA006D2EA4} 2 5 Microsoft ActiveX Data Objects 2.5 Library
' ;{420B2830-E718-11CF-893D-00A0C9054228} 1 0 Microsoft Scripting Runtime
'cells-name
' ;=scholar_search!R15C1
' ;scholar_search!_ButtonCaption
' ;=scholar_search!R3C2
' ;scholar_search!_Comment
' ;=scholar_search!R6C2
' ;scholar_search!_Contributor
' ;=scholar_search!R4C2
' ;scholar_search!_Copyright
' ;=scholar_search!R5C2
' ;scholar_search!_License
' ;=scholar_search!R2C2
' ;scholar_search!_LocalComment
' ;=scholar_search!R1C2
' ;scholar_search!_PublicName
' ;=scholar_search!R7C2
' ;scholar_search!_Since
' ;=scholar_search!R10C2
' ;scholar_search!_Tag
' ;=scholar_search!R9C2
' ;scholar_search!_Timestamp
' ;=scholar_search!R8C2
' ;scholar_search!_Url
'worksheet
' name;scholar_search/BaumMain
'cells-formula
' address;A1:B10
' ;名称
' ;scholar-search
' ;コメント
' ;学術論文や文献のWeb検索を手助けする
' ;comment
' ;Web search helper for books and papers
' ;著作権
' ;="Copyright (C) " &R[3]C & "-" & YEAR(R[5]C) & " " & R[2]C
' ;ライセンス
' ;自律, 自由, 公正, http://paidforeveryone.wordpress.com
' ;作者
' ;Tomizono - mocvba.com
' ;初版
' ;2014
' ;配布元
' ;https://github.com/osubera/scholar-search
' ;更新
' ;41981.5416666667
' ;keyword
' ;excel, book, journal, paper, article, library
' address;A13:J13
' ;ボタンの表示
' ;ボタンの機能
' ;Tag
' ;Parameter
' ;ControlType
' ;Style
' ;Width
' ;Group
' ;Action
' ;Initialize ..
' address;A15:J21
' repeat;2
' ;Google
' ;google
' skip;1
' ;1
' ;2
' skip;4
' ;Scholar
' ;Google Scholar
' ;googlescholar
' skip;1
' ;1
' ;2
' skip;4
' ;Book
' ;Google Book
' ;googlebook
' skip;1
' ;1
' ;2
' skip;1
' ;1
' skip;2
' repeat;2
' ;Amazon
' ;amazon
' skip;1
' ;1
' ;2
' skip;1
' ;1
' skip;2
' ;Cambridge
' ;Cambridge Library Search +
' ;cambridgeplus
' skip;1
' ;1
' ;2
' skip;1
' ;1
' skip;2
' ;Head
' ;Number of strings from head
' ;head
' skip;1
' ;2
' ;
' skip;1
' ;1
' skip;1
' ;0
' ;Reset
' ;Restart Browser
' ;reset
' skip;1
' ;1
' ;2
'cells-numberformat
' address;B9
' ;m/d/yyyy h:mm
'cells-width
' unit;pt
' address;B1
' ;96.75
'cells-v-align
' address;A1:J21
' repeat;210
' ;center
'code
' name;BaumMain
'{{{
Option Explicit
' BaumMain addin for ToolBarV2
' using a excel worksheet as a property holder
' we do not support popup on excel sheet at this moment
' no ideas how to describe it wisely on 2 dimensional sheet
Private Helper As ToolBarV2
Private IeHelper As BrowserHelper
Friend Function VBProjectName() As String
' VBProject.Name can't be accessed for the default settings.
VBProjectName = "F3XScholarSearch"
End Function
Friend Function GetHelper() As ToolBarV2
Set GetHelper = Helper
End Function
Friend Function GetIeHelper() As BrowserHelper
Set GetIeHelper = IeHelper
End Function
Friend Sub InitializeIeHelper()
Set IeHelper = New BrowserHelper
End Sub
Friend Sub TerminateIeHelper()
Set IeHelper = Nothing
End Sub
'=== default main procedures begin ===
' this will called by pressing a button
Public Sub BarMain(Optional oWho As Object = Nothing)
If Helper Is Nothing Then
BarInitialize
InitializeIeHelper
'MsgBox "ツールバーを修復しました。もう一度操作してください。", vbExclamation, BaumMain.Name
Else
If IeHelper Is Nothing Then InitializeIeHelper
Helper.BarMain Me
End If
End Sub
Public Sub OnButtonToggle()
Helper.OnButtonToggle
End Sub
' followings need to be public, because they are called from outside by the Helper
' we also can copy the Helper.BarMain code here, and let the followings be private.
Public Sub Menu_google(oAC As Object)
Dim Ra As Object
Set Ra = Selection
If TypeName(Ra) <> "Range" Then Exit Sub
IeHelper.Google Ra, GetUserOptions
End Sub
Public Sub Menu_googlescholar(oAC As Object)
Dim Ra As Object
Set Ra = Selection
If TypeName(Ra) <> "Range" Then Exit Sub
IeHelper.GoogleScholar Ra, GetUserOptions
End Sub
Public Sub Menu_googlebook(oAC As Object)
Dim Ra As Object
Set Ra = Selection
If TypeName(Ra) <> "Range" Then Exit Sub
IeHelper.GoogleBook Ra, GetUserOptions
End Sub
Public Sub Menu_amazon(oAC As Object)
Dim Ra As Object
Set Ra = Selection
If TypeName(Ra) <> "Range" Then Exit Sub
IeHelper.Amazon Ra, GetUserOptions
End Sub
Public Sub Menu_cambridgeplus(oAC As Object)
Dim Ra As Object
Set Ra = Selection
If TypeName(Ra) <> "Range" Then Exit Sub
IeHelper.CambridgePlus Ra, GetUserOptions
End Sub
Public Sub Menu_head(oAC As Object)
End Sub
Public Sub Menu_reset(oAC As Object)
IeHelper.RestartBrowser
End Sub
Public Function GetUserOptions() As Variant
Dim HeadLength As Long
HeadLength = Int(Val(Helper.GetControlText("head")))
GetUserOptions = Array(HeadLength)
End Function
'Public Sub Menu_edit(oAC As Object)
' Dim Ws As Worksheet
'
' If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
' Set Ws = ActiveSheet
' CompareHelper.SetEditSheet Ws, oAC
'End Sub
'
'Public Sub Menu_validate(oAC As Object)
' CompareHelper.DoValidate
'End Sub
'
'Public Sub Menu_summary(oAC As Object)
' CompareHelper.JumpTo
'End Sub
'
'Public Sub Menu_form(oAC As Object)
' CompareSheetForm.ShowVerifyCharForm
'End Sub
'
'Public Sub Menu_reset(oAC As Object)
' CompareSheetForm.ResetWindowsInTaskbar
'
' If MsgBox("設定を消去して、初期状態にしてよいですか?", vbOKCancel, "解除ボタンが押されました") = vbCancel Then Exit Sub
' CompareSheetForm.CloseVerifyCharForm
' CompareHelper.ClearSettings
'End Sub
'=== default main procedures end ===
'=== button data begin ===
Public Property Get ButtonData() As Variant
ButtonData = ConvertRangeToArray(Application.Intersect(GetButtonRow, GetButtonCol))
End Property
Public Property Get ButtonParent() As Variant
ButtonParent = Array(VBProjectName & "." & Me.CodeName)
End Property
' above simple property codes are supported by the following range helpers
Private Function GetButtonRow(Optional Address As String = "_ButtonCaption") As Range
Dim out As Range
Dim StartAt As Range
Set StartAt = Me.Range(Address)
If IsEmpty(StartAt.Offset(1, 0).Value) Then
Set out = StartAt
Else
Set out = Me.Range(StartAt, StartAt.End(xlDown))
End If
Set GetButtonRow = out.EntireRow
End Function
Private Function GetButtonCol(Optional Address As String = "_ButtonCaption") As Range
Dim StartAt As Range
Set StartAt = Me.Range(Address)
Set GetButtonCol = Me.Range(StartAt, StartAt.SpecialCells(xlCellTypeLastCell)).EntireColumn
End Function
Private Function ConvertRangeToArray(Ra As Range) As Variant
Dim out() As Variant
Dim i As Long
ReDim out(0 To Ra.Rows.Count - 1)
For i = 0 To UBound(out)
out(i) = Ra.Rows(i + 1).Value
Next
ConvertRangeToArray = out
End Function
'=== button data end ===
'=== constructor / destructor begin ===
Private Function BarName() As String
BarName = Me.Name & Me.Range("_PublicName").Text & Me.Range("_Timestamp").Text
End Function
Public Sub BarInitialize()
Dim vMe As Variant
Set vMe = Me
Set Helper = New ToolBarV2
Helper.SetName BarName
Helper.NewBar vMe
End Sub
Public Sub BarTerminate()
On Error Resume Next
Helper.DelBar
Set Helper = Nothing
End Sub
'=== constructor / destructor end ===
'}}}
'class
' name;ToolBarV2
'{{{
Option Explicit
' Generate an application toolbar
Private MyBar As Office.CommandBar
Private MyName As String
Private MyApp As Application
'=== main procedures helper begin ===
' this will called by pressing a button
Friend Sub BarMain(Optional oWho As Object = Nothing)
Dim oAC As Object ' this is the button itself pressed
Set oAC = Application.CommandBars.ActionControl
If oAC Is Nothing Then Exit Sub
' switch to a main menu procedure
Main oAC, SomebodyOrMe(oWho)
Set oAC = Nothing
End Sub
' main menu procedure. if you delete this, a public Main in Standard Module will be called, maybe.
Private Sub Main(oAC As Object, Optional oWho As Object = Nothing)
' use a button tag to switch a procedure to be called as "Menu_xx"
CallByName SomebodyOrMe(oWho), "Menu_" & oAC.Tag, VbMethod, oAC
End Sub
Public Sub Menu_about(oAC As Object)
MsgBox TypeName(Me), vbOKOnly, "Sample of procedure called by the Main"
End Sub
Friend Sub OnButtonToggle()
Dim oAC As Object ' toggle this button
Set oAC = Application.CommandBars.ActionControl
If oAC Is Nothing Then Exit Sub
ButtonSwitchToggle oAC
Set oAC = Nothing
End Sub
Private Function SomebodyOrMe(oWho As Object) As Object
If oWho Is Nothing Then
Set SomebodyOrMe = Me
Else
Set SomebodyOrMe = oWho
End If
End Function
'=== main procedures helper end ===
'=== event procedures begin ===
Private Sub Class_Initialize()
Set MyApp = Application
MyName = CStr(Timer) ' random name, maybe uniq
End Sub
Private Sub Class_Terminate()
Set MyApp = Nothing
End Sub
'=== event procedures end ===
'=== construction and destruction begin ===
Public Sub NewBar(ParamArray Addins() As Variant)
DelBar
Set MyBar = CreateBar(MyApp, MyName)
AddAddins MyBar, CVar(Addins)
ShowBar MyBar
End Sub
Public Sub DelBar()
DeleteBar MyBar
Set MyBar = Nothing
End Sub
Public Sub SetApplication(oApp As Application)
Set MyApp = oApp
End Sub
Public Sub SetName(NewName As String)
MyName = NewName
End Sub
Public Property Get Bar() As Office.CommandBar
Set Bar = MyBar
End Property
'=== construction and destruction end ===
'=== bar generator begin ===
Public Function CreateBar(oApp As Application, BarName As String) As Office.CommandBar
RemoveExistingBar oApp, BarName
Set CreateBar = oApp.CommandBars.Add(Name:=BarName, Temporary:=True)
End Function
Public Sub RemoveExistingBar(oApp As Application, BarName As String)
On Error Resume Next
oApp.CommandBars(BarName).Delete
End Sub
Public Sub DeleteBar(Bar As Object)
On Error Resume Next
Bar.Delete
End Sub
Public Sub ShowBar(Bar As Object, Optional Position As Long = msoBarTop, Optional Height As Long = 0)
Bar.Visible = True
Bar.Position = Position
If Height > 0 Then Bar.Height = Bar.Height * Height
End Sub
'=== bar generator end ===
'=== handle addins begin ===
Public Function WithAddins(ParamArray Addins() As Variant) As Long
WithAddins = AddAddins(MyBar, CVar(Addins))
End Function
Public Function AddAddins(Bar As Object, Addins As Variant) As Long
Dim Addin As Variant
Dim LastButtonIndex As Long
For Each Addin In Addins
LastButtonIndex = AddButtons(Bar, Addin.ButtonData, Addin.ButtonParent)
Next
AddAddins = LastButtonIndex
End Function
'=== handle addins end ===
'=== button generator begin ===
Public Function AddButtons(Bar As Object, Data As Variant, Parent As Variant) As Long
Dim LastButtonIndex As Long
Dim SingleData As Variant
For Each SingleData In Data
LastButtonIndex = Add(Bar, MakeAButtonData(SingleData, Parent))
Next
AddButtons = LastButtonIndex
End Function
Public Function Add(Bar As Object, Data As Variant) As Long
Dim ButtonA As CommandBarControl
Set ButtonA = Bar.Controls.Add(Type:=ButtonControlType(Data), Temporary:=True)
With ButtonA
Select Case ButtonControlType(Data)
Case msoControlEdit '2 ' textbox
Case msoControlDropdown, msoControlComboBox '3, 4 ' list and combo
SetButtonItems ButtonA, Data
SetButtonStyle ButtonA, Data
Case msoControlPopup '10 ' popup
SetButtonPopup ButtonA, Data
Case msoControlButton '1 ' Button
SetButtonStyle ButtonA, Data
SetButtonState ButtonA, Data
End Select
SetButtonWidth ButtonA, Data
SetButtonGroup ButtonA, Data
.OnAction = ButtonAction(Data)
.Caption = ButtonCaption(Data)
.TooltipText = ButtonDescription(Data)
.Tag = ButtonTag(Data)
.Parameter = ButtonParameter(Data)
End With
Add = ButtonA.Index
Set ButtonA = Nothing
End Function
Public Sub Remove(Bar As Object, Items As Variant)
On Error Resume Next
Dim Item As Variant
If IsArray(Item) Then
For Each Item In Items
Remove Bar, Item
Next
Else
Bar.Controls(Item).Delete
End If
End Sub
'=== button generator end ===
'=== button data structure begin ===
' generator / selector
' Data(): Array of button data
' Parent(): Array of button parent information (bar and properties)
' Parent(0) is reserved for addin key
Public Function MakeAButtonData(Data As Variant, Parent As Variant) As Variant
MakeAButtonData = Array(NormalizeArray(Data), Parent)
End Function
Public Function DataAButtonData(AButtonData As Variant) As Variant
On Error Resume Next
DataAButtonData = AButtonData(0)
End Function
Public Function ParentAButtonData(AButtonData As Variant) As Variant
On Error Resume Next
ParentAButtonData = AButtonData(1)
End Function
Public Function KeyAButtonData(AButtonData As Variant) As String
On Error Resume Next
KeyAButtonData = ParentAButtonData(AButtonData)(0)
End Function
Public Function ItemAButtonData(AButtonData As Variant, ByVal Item As Long, _
Optional FallBack As Variant = Empty) As Variant
On Error Resume Next
Dim out As Variant
out = DataAButtonData(AButtonData)(Item)
If IsEmpty(out) Then out = FallBack
ItemAButtonData = out
End Function
'=== button data structure end ===
'=== button data struncture detail begin ===
Public Function ButtonCaption(Data As Variant) As String
ButtonCaption = ItemAButtonData(Data, 0)
End Function
Public Function ButtonDescription(Data As Variant) As String
ButtonDescription = ItemAButtonData(Data, 1)
End Function
Public Function ButtonTag(Data As Variant) As String
ButtonTag = ItemAButtonData(Data, 2, ButtonCaption(Data))
End Function
Public Function ButtonParameter(Data As Variant) As String
ButtonParameter = ItemAButtonData(Data, 3)
End Function
Public Function ButtonControlType(Data As Variant) As Long
'MsoControlType
On Error Resume Next
ButtonControlType = Val(ItemAButtonData(Data, 4, msoControlButton))
End Function
Public Function ButtonStyle(Data As Variant) As Long
'MsoButtonStyle
On Error Resume Next
ButtonStyle = Val(ItemAButtonData(Data, 5, msoButtonCaption))
End Function
Public Function ButtonWidth(Data As Variant) As Long
' we use 45 units here
On Error Resume Next
Const UnitWidth = 45
ButtonWidth = Val(ItemAButtonData(Data, 6)) * UnitWidth
End Function
Public Function ButtonGroup(Data As Variant) As Boolean
' put group line on its left
ButtonGroup = Not IsEmpty(ItemAButtonData(Data, 7))
End Function
Public Function ButtonAction(Data As Variant) As String
On Error Resume Next
' Standard Method Name to be kicked with the button
Const BarMain = "BarMain"
Dim FullName As String
If KeyAButtonData(Data) = "" Then
FullName = BarMain
Else
FullName = KeyAButtonData(Data) & "." & BarMain
End If
ButtonAction = ItemAButtonData(Data, 8, FullName)
End Function
Public Function ButtonItems(Data As Variant) As Variant
Dim pan As Variant
Dim i As Long
On Error GoTo DONE
pan = Empty
i = 9
Do Until IsEmpty(ItemAButtonData(Data, i))
pan = Array(ItemAButtonData(Data, i), pan)
i = i + 1
Loop
DONE:
ButtonItems = pan
End Function
'=== button data struncture detail end ===
'=== button tools for data begin ===
Public Sub SetButtonWidth(ButtonA As CommandBarControl, Data As Variant)
If ButtonWidth(Data) > 0 Then ButtonA.Width = ButtonWidth(Data)
End Sub
Public Sub SetButtonStyle(ButtonA As Object, Data As Variant)
On Error Resume Next
' Each Button does not accept each style, but we won't check them.
If ButtonStyle(Data) <> 0 Then ButtonA.Style = ButtonStyle(Data)
End Sub
Public Sub SetButtonGroup(ButtonA As CommandBarControl, Data As Variant)
If ButtonGroup(Data) Then ButtonA.BeginGroup = True
End Sub
Public Sub SetButtonItems(ButtonA As Object, Data As Variant)
Dim pan As Variant
Dim HasItem As Boolean
pan = ButtonItems(Data)
HasItem = False
Do Until IsEmpty(pan)
ButtonA.AddItem pan(0), 1
pan = pan(1)
HasItem = True
Loop
If HasItem Then ButtonA.ListIndex = 1
End Sub
Public Sub SetButtonPopup(ButtonA As CommandBarControl, Data As Variant)
Dim MyChild As Variant
MyChild = StackToArray(ButtonItems(Data))
If UBound(MyChild) >= 0 Then Add ButtonA, MyChild
End Sub
Public Sub SetButtonState(ButtonA As Object, Data As Variant)
If Not IsEmpty(ButtonItems(Data)) Then ButtonA.State = msoButtonDown
End Sub
'=== button tools for data end ===
'=== button tools for control object begin ===
Public Sub ComboAddHistory(oAC As Object, Optional AtBottom As Boolean = False)
If oAC.ListIndex > 0 Then Exit Sub
If AtBottom Then
oAC.AddItem oAC.Text
oAC.ListIndex = oAC.ListCount
Else
oAC.AddItem oAC.Text, 1
oAC.ListIndex = 1
End If
End Sub
Public Sub ListAddHistory(oAC As Object, Text As String, Optional AtBottom As Boolean = False)
If AtBottom Then
oAC.AddItem Text
oAC.ListIndex = oAC.ListCount
Else
oAC.AddItem Text, 1
oAC.ListIndex = 1
End If
End Sub
Public Function ListFindIndex(oAC As Object, Text As String) As Long
Dim i As Long
For i = 1 To oAC.ListCount
If oAC.List(i) = Text Then
ListFindIndex = i
Exit Function
End If
Next
ListFindIndex = 0
End Function
Public Function ControlText(oAC As Object) As String
ControlText = oAC.Text
End Function
Public Sub ButtonSwitchOn(oAC As Object)
oAC.State = msoButtonDown
End Sub
Public Sub ButtonSwitchOff(oAC As Object)
oAC.State = msoButtonUp
End Sub
Public Function ButtonSwitchToggle(oAC As Object) As Boolean
ButtonSwitchToggle = (Not IsButtonStateOn(oAC))
If ButtonSwitchToggle Then
ButtonSwitchOn oAC
Else
ButtonSwitchOff oAC
End If
End Function
Public Function IsButtonStateOn(oAC As Object) As Boolean
IsButtonStateOn = (oAC.State = msoButtonDown)
End Function
Public Function ButtonFindByTag(oAC As Object, Tag As Variant) As CommandBarControl
If oAC Is Nothing Then Exit Function
If TypeName(oAC) = "CommandBar" Then
Set ButtonFindByTag = oAC.FindControl(Tag:=Tag)
Else
Set ButtonFindByTag = oAC.Parent.FindControl(Tag:=Tag)
End If
End Function
'=== button tools for control object end ===
'=== button tools for mybar begin ===
Public Function GetButton(TagOrIndex As Variant) As Office.CommandBarControl
On Error Resume Next
Select Case TypeName(TagOrIndex)
Case "Long", "Integer", "Byte", "Double", "Single"
Set GetButton = MyBar.Controls(TagOrIndex)
Case Else
Set GetButton = ButtonFindByTag(MyBar, TagOrIndex)
End Select
End Function
Public Function GetControlText(TagOrIndex As Variant) As String
Dim out As String
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
Select Case oAC.Type
Case msoControlEdit, msoControlDropdown, msoControlComboBox
out = oAC.Text
Case Else ' msoControlButton, msoControlPopup
out = oAC.Caption
End Select
Set oAC = Nothing
GetControlText = out
End Function
Public Function SetControlText(TagOrIndex As Variant, ByVal Text As String) As Boolean
Dim out As Boolean
Dim oAC As Office.CommandBarControl
Dim Index As Long
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then
out = False
Else
Select Case oAC.Type
Case msoControlEdit
oAC.Text = Text
Case msoControlDropdown
Index = ListFindIndex(oAC, Text)
If Index = 0 Then
ListAddHistory oAC, Text
Else
oAC.ListIndex = Index
End If
Case msoControlComboBox
Index = ListFindIndex(oAC, Text)
If Index = 0 Then
oAC.Text = Text
ComboAddHistory oAC
Else
oAC.ListIndex = Index
End If
Case Else
oAC.Caption = Text
End Select
Set oAC = Nothing
out = True
End If
SetControlText = out
End Function
Public Function GetControlState(TagOrIndex As Variant) As Boolean
Dim out As Boolean
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
out = False
If oAC.Type = msoControlButton Then
' return True when the button is pushed down
out = IsButtonStateOn(oAC)
End If
Set oAC = Nothing
GetControlState = out
End Function
Public Function SetControlState(TagOrIndex As Variant, ByVal State As Boolean) As Boolean
Dim out As Boolean
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
out = False
If oAC.Type = msoControlButton Then
If IsButtonStateOn(oAC) <> State Then
If State Then
ButtonSwitchOn oAC
Else
ButtonSwitchOff oAC
End If
' return True when the status is strictly changed
out = True
End If
End If
Set oAC = Nothing
SetControlState = out
End Function
Public Function GetControlVisible(TagOrIndex As Variant) As Boolean
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
GetControlVisible = oAC.Visible
End Function
Public Function SetControlVisible(TagOrIndex As Variant, ByVal Visible As Boolean) As Boolean
Dim out As Boolean
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
out = False
If oAC.Visible <> Visible Then
oAC.Visible = Visible
' return True when the visible is strictly changed
out = True
End If
SetControlVisible = out
End Function
Public Function IncControlWidth(TagOrIndex As Variant, ByVal Width As Long) As Long
Dim out As Long
Dim oAC As Office.CommandBarControl
Set oAC = GetButton(TagOrIndex)
If oAC Is Nothing Then Exit Function
On Error Resume Next
oAC.Width = oAC.Width + Width
' return the width accepted (tips: setting 0 to width makes it becomes default)
out = oAC.Width
IncControlWidth = out
End Function
'=== button tools for mybar end ===
'=== helper functions begin ===
Public Function NormalizeArray(x As Variant) As Variant
On Error Resume Next
Dim out() As Variant
Dim i As Long
Dim L1 As Long
Dim L2 As Long
Dim U1 As Long
Dim U2 As Long
L1 = 0
L2 = 0
U1 = -1
U2 = -1
L1 = LBound(x)
L2 = LBound(x, 2) ' error unless 2 dimensions
U1 = UBound(x)
U2 = UBound(x, 2) ' error unless 2 dimensions
If U1 < L1 Then
NormalizeArray = Array()
Exit Function
End If
If U2 = -1 Then
ReDim out(0 To U1 - L1)
For i = 0 To UBound(out)
out(i) = x(i + L1)
Next
Else
ReDim out(0 To U2 - L2)
For i = 0 To UBound(out)
out(i) = x(L1, i + L2)
' we pick up the 1st line only
Next
End If
NormalizeArray = out
End Function
Public Function StackToArray(pan As Variant) As Variant
Dim out() As Variant
Dim x As Variant
Dim i As Long
Dim Counter As Long