-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparesWeb_1_4_6_Module1.bas
1349 lines (1315 loc) · 56.7 KB
/
SparesWeb_1_4_6_Module1.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
Attribute VB_Name = "Module1"
'v1.4.6 / 09.11.2024 [alxcor:241109]
Sub conClearAll(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
clearAll
ElseIf (ActiveSheet.Name = "Report") Then
clearAllR
Else
MsgBox ("'Clear All' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conSetHeader(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
setHeader
ElseIf (ActiveSheet.Name = "Report") Then
setHeaderR
Else
MsgBox ("'Set Header' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conReadRow(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
readRow
MsgBox "Done!"
ElseIf (ActiveSheet.Name = "Report") Then
readRowR
MsgBox "Done!"
Else
MsgBox ("'Read Row' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conReadAll(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
readAll
MsgBox "Done!"
ElseIf (ActiveSheet.Name = "Report") Then
readAllR
MsgBox "Done!"
Else
MsgBox ("'Read All' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conSuccessorR(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
checkSuccessor
MsgBox "Done!"
ElseIf (ActiveSheet.Name = "Report") Then
'checkSuccessorR
MsgBox ("'Check Successor' should be called from 'Report' sheet")
Else
MsgBox ("'Check Successor' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conSuccessorA(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
checkSuccessorAll
MsgBox "Done!"
ElseIf (ActiveSheet.Name = "Report") Then
MsgBox ("'Check Successor' should be called from 'Report' sheet")
Else
MsgBox ("'Check Successor' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conReport(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
Report
ElseIf (ActiveSheet.Name = "Report") Then
Report
Else
MsgBox ("'Report' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conFormat(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
FormatReport
ElseIf (ActiveSheet.Name = "Report") Then
FormatReport
Else
MsgBox ("'FormatReport' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conSow(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
displSOW
ElseIf (ActiveSheet.Name = "Report") Then
displSOW
Else
MsgBox ("'Spares on Web' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conMall(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
displMall
ElseIf (ActiveSheet.Name = "Report") Then
displMall
Else
MsgBox ("'Industry Mall' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conSios(control As IRibbonControl)
If (ActiveSheet.Name = "Data") Then
displSios
ElseIf (ActiveSheet.Name = "Report") Then
displSios
Else
MsgBox ("'Industry Support' should be called from 'Data' sheet or from 'Report' sheet")
End If
End Sub
Sub conOpenWeb(control As IRibbonControl)
ActiveWorkbook.FollowHyperlink ("https://alxcor.github.io/camxls")
End Sub
Sub conOpenGit(control As IRibbonControl)
ActiveWorkbook.FollowHyperlink ("https://github.com/alxcor/camxls")
End Sub
Sub clearAll()
'Worksheet 'Data': Clear All
Sheets("Data").Activate
Cells.Clear
Cells.ColumnWidth = 8.5
Cells.Rows.AutoFit
ActiveWindow.FreezePanes = False
Cells(1, 1).Select
End Sub
Sub clearAllR()
'Worksheet 'Report': Clear All
Sheets("Report").Activate
Cells.Clear
Cells.ColumnWidth = 8.5
Cells.Rows.AutoFit
ActiveWindow.FreezePanes = False
Cells(1, 1).Select
End Sub
Sub setHeader()
'Worksheet 'Data': Set header texts on row 1
Dim rowNumber As Integer
Dim maxCol As Integer
rowNumber = 1
maxCol = 29
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'Select First Row and check if the row is free for header:
If (Cells(1, 1) <> "") Then
If (Cells(1, 1) <> "Your Data...") Then
Range("A1").EntireRow.Insert
End If
End If
'Clear the first row
Range(Cells(rowNumber, 1), Cells(rowNumber, maxCol)).Rows.Clear
'Set texts
Cells(rowNumber, 1) = "Your Data..."
Cells(rowNumber, 2) = "MLFB"
Cells(rowNumber, 3) = "Product Description"
Cells(rowNumber, 4) = "Product family"
Cells(rowNumber, 5) = "Product Lifecycle (PLM)"
Cells(rowNumber, 6) = "PLM Effective Date"
Cells(rowNumber, 7) = "Notes"
Cells(rowNumber, 8) = "Price Group"
Cells(rowNumber, 9) = "Surcharge for Raw Materials"
Cells(rowNumber, 10) = "Metal Factor"
Cells(rowNumber, 11) = "Export Control Regulations"
Cells(rowNumber, 12) = "Dispatch Time"
Cells(rowNumber, 13) = "Net Weight (kg)"
Cells(rowNumber, 14) = "Product Dimensions (W x L x H)"
Cells(rowNumber, 15) = "Packaging Dimension"
Cells(rowNumber, 16) = "Package size unit of measure"
Cells(rowNumber, 17) = "Quantity Unit"
Cells(rowNumber, 18) = "Packaging Quantity"
Cells(rowNumber, 19) = "EAN"
Cells(rowNumber, 20) = "UPC"
Cells(rowNumber, 21) = "Commodity Code"
Cells(rowNumber, 22) = "KZ_FDB/ CatalogID"
Cells(rowNumber, 23) = "Product Group"
Cells(rowNumber, 24) = "Country of origin"
Cells(rowNumber, 25) = "Compliance with the substance restrictions according to RoHS directive"
Cells(rowNumber, 26) = "Product class"
Cells(rowNumber, 27) = "Obligation Category for taking back electrical and electronic equipment after use"
Cells(rowNumber, 28) = "Classifications"
Cells(rowNumber, 29) = "Successor"
Cells(rowNumber, 1).EntireRow.Font.Bold = True
'Set borders
With Range(Cells(rowNumber, 1), Cells(rowNumber, maxCol)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
'Set Column width
setSize
End Sub
Sub setHeaderR()
'Worksheet 'Report': Set header texts on row 1
Dim rowNumber As Integer
Dim maxCol As Integer
rowNumber = 1
maxCol = 5
'Select Data worksheet
Sheets("Report").Activate
DoEvents
'Select First Row and check if the row is free for header:
If (Cells(1, 1) <> "") Then
If (Cells(1, 1) <> "MLFB") Then
Range("A1").EntireRow.Insert
End If
End If
'Select Second Row and check if the row is free for header:
If (Cells(2, 1) <> "") Then
If (Left(Cells(2, 1), 6) <> "Active") Then
Range("A1").EntireRow.Insert
End If
End If
'Write header on first row
rowNumberR = 1
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Name = "Arial"
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Size = 10
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.TintAndShade = 0
Sheets("Report").Cells(rowNumberR, 1) = "MLFB"
Sheets("Report").Cells(rowNumberR, 2) = "Product Description"
Sheets("Report").Cells(rowNumberR, 3) = "Product Lifecycle (PLM)"
Sheets("Report").Cells(rowNumberR, 4) = "Notes"
Sheets("Report").Cells(rowNumberR, 5) = "Dispatch Time"
'Format cells
Sheets("Report").Cells.VerticalAlignment = xlTop
Sheets("Report").Cells(rowNumberR, 1).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 1).EntireColumn.ColumnWidth = 18
Sheets("Report").Cells(rowNumberR, 2).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 2).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 3).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 3).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 4).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 4).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 5).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 5).EntireColumn.ColumnWidth = 8
rowNumberR = 2
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Name = "Arial"
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Size = 10
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.TintAndShade = 0
'some final formatting
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).TintAndShade = 0
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).Weight = xlThick
Sheets("Report").Cells(2, 1).Interior.Color = RGB(125, 242, 92)
Sheets("Report").Cells(2, 2).Interior.Color = RGB(229, 242, 80)
Sheets("Report").Cells(2, 3).Interior.Color = RGB(242, 135, 148)
Sheets("Report").Cells(2, 4).Interior.Color = RGB(230, 230, 230)
Sheets("Report").Cells(2, 5).Interior.Color = RGB(230, 230, 230)
DoEvents
'Set borders
With Range(Cells(rowNumber, 1), Cells(rowNumber, maxCol)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
End Sub
Sub setSize()
'Worksheet 'Data': Set Row/Column size
'Select Data worksheet
Sheets("Data").Activate
Columns(1).EntireColumn.WrapText = False
Columns(1).EntireColumn.AutoFit
Columns(2).EntireColumn.WrapText = False
Columns(2).EntireColumn.AutoFit
Columns(3).EntireColumn.WrapText = True
Columns(3).EntireColumn.ColumnWidth = 40
Columns(4).EntireColumn.WrapText = True
Columns(4).EntireColumn.ColumnWidth = 24
Columns(5).EntireColumn.WrapText = True
Columns(5).EntireColumn.ColumnWidth = 24
Columns(6).EntireColumn.WrapText = True
Columns(6).EntireColumn.ColumnWidth = 18
Columns(7).EntireColumn.WrapText = True
Columns(7).EntireColumn.ColumnWidth = 40
Columns(8).EntireColumn.WrapText = True
Columns(8).EntireColumn.ColumnWidth = 12
Columns(9).EntireColumn.WrapText = True
Columns(9).EntireColumn.ColumnWidth = 30
Columns(10).EntireColumn.WrapText = True
Columns(10).EntireColumn.ColumnWidth = 12
Columns(11).EntireColumn.WrapText = True
Columns(11).EntireColumn.ColumnWidth = 26
Columns(12).EntireColumn.WrapText = True
Columns(12).EntireColumn.ColumnWidth = 14
Columns(13).EntireColumn.WrapText = True
Columns(13).EntireColumn.ColumnWidth = 16
Columns(14).EntireColumn.WrapText = True
Columns(14).EntireColumn.ColumnWidth = 30
Columns(15).EntireColumn.WrapText = True
Columns(15).EntireColumn.ColumnWidth = 22
Columns(16).EntireColumn.WrapText = True
Columns(16).EntireColumn.ColumnWidth = 28
Columns(17).EntireColumn.WrapText = True
Columns(17).EntireColumn.ColumnWidth = 12
Columns(18).EntireColumn.WrapText = True
Columns(18).EntireColumn.ColumnWidth = 20
Columns(19).EntireColumn.WrapText = True
Columns(19).EntireColumn.ColumnWidth = 16
Columns(20).EntireColumn.WrapText = True
Columns(20).EntireColumn.ColumnWidth = 16
Columns(21).EntireColumn.WrapText = True
Columns(21).EntireColumn.ColumnWidth = 16
Columns(22).EntireColumn.WrapText = True
Columns(22).EntireColumn.ColumnWidth = 16
Columns(23).EntireColumn.WrapText = True
Columns(23).EntireColumn.ColumnWidth = 16
Columns(24).EntireColumn.WrapText = True
Columns(24).EntireColumn.ColumnWidth = 16
Columns(25).EntireColumn.WrapText = True
Columns(25).EntireColumn.ColumnWidth = 40
Columns(26).EntireColumn.WrapText = True
Columns(26).EntireColumn.ColumnWidth = 40
Columns(27).EntireColumn.WrapText = True
Columns(27).EntireColumn.ColumnWidth = 40
Columns(28).EntireColumn.WrapText = True
Columns(28).EntireColumn.ColumnWidth = 40
Columns(29).EntireColumn.WrapText = True
Columns(29).EntireColumn.ColumnWidth = 40
Cells(1, 1).EntireRow.Font.Bold = True
Cells(1, 1).EntireRow.WrapText = False
Cells.Rows.AutoFit
End Sub
Sub setCells(rowNumber)
'clear data for a range of cells in a row
Dim maxCol As Integer
Dim mlfbCode As String
'last column is AC = column 29
maxCol = 29
mlfbCode = Cells(rowNumber, 1)
'clear data for current row, columns 1 to maxCol
With Range(Cells(rowNumber, 1), Cells(rowNumber, maxCol))
.Clear
.VerticalAlignment = xlTop
End With
Cells(rowNumber, 1).Value = mlfbCode
End Sub
Sub readRow()
'read data for current row: on column 1 [A] should be a product code (MLFB) from Industry Mall web site
Dim rowNumber As Long
Dim mlfbCode As String
Dim isSuccessor As Boolean
'--------------------------------------------
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'--------------------------------------------
rowNumber = ActiveCell.Row
If rowNumber < 2 Then
MsgBox ("[EN]: Table starts on row 2; [RO]:Tabelul incepe de la randul 2!")
GoTo EndSub
Else
'----------------------------------------
Call setCells(rowNumber)
'----------------------------------------
mlfbCode = Cells(rowNumber, 1).Value
isSuccessor = False
If Len(mlfbCode) > 1 Then
'remove successor note from code
If (Left(mlfbCode, 8) = ("[succ.]" + vbLf)) Then
mlfbCode = Right(mlfbCode, Len(mlfbCode) - 8)
isSuccessor = True
End If
If (Left(mlfbCode, 7) = "[succ.]") Then
mlfbCode = Right(mlfbCode, Len(mlfbCode) - 7)
isSuccessor = True
End If
Call ImportSieMallIntra(mlfbCode, rowNumber)
If (isSuccessor = True) Then
'Add successor note to column2
Cells(rowNumber, 2).Value = "[succ.]" + vbLf + Cells(rowNumber, 2).Value
End If
End If
End If
'--------------------------------------------
setHeader
setSize
'--------------------------------------------
Application.StatusBar = ""
EndSub:
End Sub
Sub readRowR()
'read data starting from 'Report' worksheet
Dim rowNumber As Long
Dim mlfbCode As String
'--------------------------------------------
'Select Report worksheet
Sheets("Report").Activate
DoEvents
'--------------------------------------------
rowNumber = ActiveCell.Row
If rowNumber < 3 Then
MsgBox ("[EN]: Table starts on row 3; [RO]:Tabelul incepe de la randul 3!")
GoTo EndSub
Else
mlfbCode = Cells(rowNumber, 1).Value
Call setCells(rowNumber)
Sheets("Data").Activate
DoEvents
setHeader
DoEvents
Cells(rowNumber - 1, 1).Select
Cells(rowNumber - 1, 1).Value = mlfbCode
DoEvents
readRow
ReportRow
End If
Sheets("Report").Activate
Cells(rowNumber, 1).Select
'--------------------------------------------
Application.StatusBar = ""
EndSub:
End Sub
Sub readAll()
'read data for all non-empty rows >= 2: on column 1 [A] should be a product code (MLFB) from Industry Mall web site
Dim rowNumber As Long
Dim mlfbCode As String
Dim iCounter As Integer
Dim isSuccessor As Boolean
Dim maxRow As Integer
'set a maximum of 500 rows
maxRow = 500
'--------------------------------------------
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'--------------------------------------------
setHeader
'--------------------------------------------
For rowNumber = 2 To 500
Call setCells(rowNumber)
'----------------------------------------
mlfbCode = Cells(rowNumber, 1).Value
isSuccessor = False
If Len(mlfbCode) > 1 Then
'remove successor note from code
If (Left(mlfbCode, 8) = ("[succ.]" + vbLf)) Then
mlfbCode = Right(mlfbCode, Len(mlfbCode) - 8)
isSuccessor = True
End If
If (Left(mlfbCode, 7) = "[succ.]") Then
mlfbCode = Right(mlfbCode, Len(mlfbCode) - 7)
isSuccessor = True
End If
Cells(rowNumber, 1).Select
Call ImportSieMallIntra(mlfbCode, rowNumber)
If (isSuccessor = True) Then
'Add successor note to column2
Cells(rowNumber, 2).Value = "[succ.]" + vbLf + Cells(rowNumber, 2).Value
End If
End If
DoEvents
Next
'--------------------------------------------
setHeader
setSize
'--------------------------------------------
Application.StatusBar = ""
Range("A2").Select
ActiveWindow.FreezePanes = True
EndSub:
End Sub
Sub readAllR()
'read data starting from 'Report' worksheet
Dim rowNumber As Long
Dim mlfbCode As String
Dim iCounter As Integer
Dim maxRow As Integer
'set a maximum of 500 rows
maxRow = 500
'--------------------------------------------
setHeaderR
'--------------------------------------------
clearAll
DoEvents
'--------------------------------------------
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'--------------------------------------------
setHeader
'--------------------------------------------
For rowNumber = 2 To 500
Cells(rowNumber, 1).Value = Sheets("Report").Cells(rowNumber + 1, 1).Value
DoEvents
Next
readAll
Report
End Sub
Sub checkSuccessor()
'check successor; if a successor is found in column 29 a new row is added and data is read
Dim rowNumber As Long
Dim mlfbCode As String
'--------------------------------------------
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'--------------------------------------------
rowNumber = ActiveCell.Row
If rowNumber < 2 Then
MsgBox ("[EN]: Table starts on row 2; [RO]:Tabelul incepe de la randul 2!")
GoTo EndSub
Else
mlfbCode = Cells(rowNumber, 29).Value
If (("[succ.]" + vbLf + mlfbCode <> Cells(rowNumber + 1, 1).Value) And (mlfbCode <> Cells(rowNumber + 1, 1).Value)) Then
If (mlfbCode <> "") Then
Cells(rowNumber + 1, 1).EntireRow.Insert
Cells(rowNumber + 1, 1).Value = "[succ.]" + vbLf + mlfbCode
setCells (rowNumer + 1)
Call ImportSieMallIntra(mlfbCode, rowNumber + 1)
'Add successor note to column2
Cells(rowNumber + 1, 2).Value = "[succ.]" + vbLf + Cells(rowNumber + 1, 2).Value
Cells(rowNumber + 1, 1).Activate
End If
End If
End If
'--------------------------------------------
setHeader
setSize
'--------------------------------------------
Application.StatusBar = ""
EndSub:
End Sub
Sub checkSuccessorR()
'check successor from Report worksheet
MsgBox "Successor should be checked from Data worksheet..."
End Sub
Sub checkSuccessorAll()
'check all rows for successors; if a successor is found in column 29 a new row is added and data is read
Dim rowNumber As Long
Dim mlfbCode As String
Dim iCounter As Integer
Dim maxRow As Integer
'set a maximum of 500 rows
maxRow = 500
'--------------------------------------------
'Select Data worksheet
Sheets("Data").Activate
DoEvents
'--------------------------------------------
setHeader
'--------------------------------------------
rowNumber = 2
While (rowNumber <= maxRow)
Cells(rowNumber, 1).Select
DoEvents
mlfbCode = Cells(rowNumber, 29).Value
If (("[succ.]" + vbLf + mlfbCode <> Cells(rowNumber + 1, 1).Value) And (mlfbCode <> Cells(rowNumber + 1, 1).Value)) Then
If (mlfbCode <> "") Then
Cells(rowNumber + 1, 1).EntireRow.Insert
Cells(rowNumber + 1, 1).Value = "[succ.]" + vbLf + mlfbCode
setCells (rowNumer + 1)
Call ImportSieMallIntra(mlfbCode, rowNumber + 1)
'Add successor note to column2
Cells(rowNumber + 1, 2).Value = "[succ.]" + vbLf + Cells(rowNumber + 1, 2).Value
maxRow = maxRow + 1
End If
End If
rowNumber = rowNumber + 1
Wend
'--------------------------------------------
setHeader
setSize
'--------------------------------------------
Application.StatusBar = ""
Range("A2").Select
ActiveWindow.FreezePanes = True
EndSub:
End Sub
Sub ImportSieMallIntra(mlfbCode, rowNumber)
'read data for a specific product code (MLFB) from Industry Mall web site
'netMode = xmlHTTP version
On Error GoTo ErrHand: 'disable this line to see what is the error
Dim targetURL As String
Dim webContent As String
Dim index As Integer
Dim DetailNo As Integer
Dim Product As Object
'--------------------------------------------
Cells(rowNumber, 2).Value = mlfbCode
Cells(rowNumber, 5).Value = "ERR: Not Found!!!"
Cells(rowNumber, 5).Interior.Color = RGB(242, 135, 148)
'Reading web page in buffer...
'write status in StatusBar...
Application.StatusBar = "Trying to connect to Industry Mall... MLFB: " + mlfbCode
'options should be separated by space instead of +
mlfbCode = Replace(mlfbCode, "+", "%20")
'format spaces html style
mlfbCode = Replace(mlfbCode, " ", "%20")
'clear front and back spaces
mlfbCode = Replace(mlfbCode, "%20", " ")
mlfbCode = Trim(mlfbCode)
mlfbCode = Replace(mlfbCode, " ", "%20")
'set web page (for scrapper)
targetURL = "https://mall.industry.siemens.com/mall/en/WW/Catalog/Product/" + mlfbCode
'--------------------------------------------
'xmlHTTP version
Application.StatusBar = "Trying to connect -via xmlHTTP- to Industry Mall... MLFB: " + mlfbCode
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
xmlhttp.Open "GET", targetURL, False
xmlhttp.send
'MsgBox (xmlhttp.responseText)
Dim htmldoc As Object
Set htmldoc = CreateObject("HTMLFile")
htmldoc.body.innerHTML = xmlhttp.responseText
Application.StatusBar = "..."
'MsgBox (htmldoc.body.innerHTML)
'See content of the web-page for diagnosis purposes...
'MsgBox html.documentElement.innerHTML
DoEvents
index = 1
DetailNo = 1
'Search for ID-content in web page
Set Product = htmldoc.getElementById("content")
Set ProductDetails = Product.all
Application.StatusBar = "Trying to get details for MLFB: " + mlfbCode
For Each Detail In ProductDetails
'MLFB code...
If Detail.className = "detailsPageHeader" Then
'If Detail.className = "productIdentifier" Then
Cells(rowNumber, 2).Value = Detail.innerText
End If
'Produs details - Extract from table:
If Detail.className = "ProductDetailsTable" Then
'Get all details for the product
Set Details = Detail.all
'Count details fields
DetailNo = Details.Length
For index = 0 To DetailNo - 1
'Product Description
If (Details(index).innerText = "Product Description") And (index < DetailNo - 1) Then
Cells(rowNumber, 3) = Details(index + 1).innerText
End If
'Product Family
If (Details(index).innerText = "Product family") And (index < DetailNo - 1) Then
Cells(rowNumber, 4) = Details(index + 1).innerText
End If
'Product Lifecycle(PLM)
If (Details(index).innerText = "Product Lifecycle (PLM)") And (index < DetailNo - 1) Then
Cells(rowNumber, 5) = Details(index + 1).innerText
'PLM status:
sTemp = Details(index + 1).innerText
iTemp = InStr(1, sTemp, "M250", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M280", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M300", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M400", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(229, 242, 80)
End If
iTemp = InStr(1, sTemp, "M410", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(229, 242, 80)
End If
iTemp = InStr(1, sTemp, "M490", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(242, 135, 148)
End If
iTemp = InStr(1, sTemp, "M500", vbTextCompare)
If iTemp > 0 Then
Cells(rowNumber, 5).Interior.Color = RGB(242, 135, 148)
End If
End If
'PLM Effective Date
If (Details(index).innerText = "PLM Effective Date") And (index < DetailNo - 1) Then
Cells(rowNumber, 6) = Details(index + 1).innerText
End If
'Notes
If (Details(index).innerText = "Notes") And (index < DetailNo - 1) Then
Cells(rowNumber, 7) = Details(index + 1).innerText
'sTemp = Details(index + 1).innerText
'iTemp = InStr(1, sTemp, "Successor", vbTextCompare)
'iTemp2 = Len(sTemp)
'If (iTemp > 0) And ((iTemp2 - iTemp > 11)) Then
'iTemp = iTemp + 11
'sTemp = Mid(sTemp, iTemp, iTemp2 - iTemp)
''Successor: attempt to identify MLFB for successor product
'Cells(rowNumber, 29) = sTemp
'End If
If Cells(rowNumber, 7).Value <> "" Then
Cells(rowNumber, 7).Interior.Color = RGB(91, 155, 213)
End If
End If
'Price Group
If (Details(index).innerText = "Price Group") And (index < DetailNo - 1) Then
Cells(rowNumber, 8) = Details(index + 1).innerText
End If
'New Price Group [230209]
If (Details(index).innerText = "Region Specific PriceGroup / Headquarter Price Group") And (index < DetailNo - 1) Then
Cells(rowNumber, 8) = Details(index + 1).innerText
End If
'Surcharge for Raw Materials
If (Details(index).innerText = "Surcharge for Raw Materials") And (index < DetailNo - 1) Then
Cells(rowNumber, 9) = Details(index + 1).innerText
End If
'Surcharge for Metal Factor
If (Details(index).innerText = "Metal Factor") And (index < DetailNo - 1) Then
Cells(rowNumber, 10) = Details(index + 1).innerText
End If
'Export Control Regulations
If (Details(index).innerText = "Export Control Regulations") And (index < DetailNo - 1) Then
Cells(rowNumber, 11) = Details(index + 1).innerText
End If
'Delivery Time
If (Details(index).innerText = "Delivery Time") And (index < DetailNo - 1) Then
Cells(rowNumber, 12) = Details(index + 1).innerText
End If
'New Delivery Time [230209]
If (Details(index).innerText = "Standard lead time ex-works") And (index < DetailNo - 1) Then
Cells(rowNumber, 12) = Details(index + 1).innerText
End If
'New Delivery Time [240410]
If (Details(index).innerText = "Estimated dispatch time (Working Days)") And (index < DetailNo - 1) Then
Cells(rowNumber, 12) = Details(index + 1).innerText
End If
'Net Weight(kg)
If (Details(index).innerText = "Net Weight(kg)") And (index < DetailNo - 1) Then
Cells(rowNumber, 13) = Details(index + 1).innerText
End If
'New Net Weight(kg) [230209]
If (Details(index).innerText = "Net Weight (kg)") And (index < DetailNo - 1) Then
Cells(rowNumber, 13) = Details(index + 1).innerText
End If
'Product Dimensions (W x L x H)
If (Details(index).innerText = "Product Dimensions (W x L x H)") And (index < DetailNo - 1) Then
Cells(rowNumber, 14) = Details(index + 1).innerText
End If
'Packaging Not Dimension
If (Details(index).innerText = "Packaging Dimension") And (index < DetailNo - 1) Then
Cells(rowNumber, 15) = Details(index + 1).innerText
End If
'Package size unit of measure
If (Details(index).innerText = "Package size unit of measure") And (index < DetailNo - 1) Then
Cells(rowNumber, 16) = Details(index + 1).innerText
End If
'Quantity Unit
If (Details(index).innerText = "Quantity Unit") And (index < DetailNo - 1) Then
Cells(rowNumber, 17) = Details(index + 1).innerText
End If
'Packaging Quantity
If (Details(index).innerText = "Packaging Quantity") And (index < DetailNo - 1) Then
Cells(rowNumber, 18) = Details(index + 1).innerText
End If
'EAN
If (Details(index).innerText = "EAN") And (index < DetailNo - 1) Then
Cells(rowNumber, 19) = "'" & Details(index + 1).innerText
End If
'UPC
If (Details(index).innerText = "UPC") And (index < DetailNo - 1) Then
Cells(rowNumber, 20) = "'" & Details(index + 1).innerText
End If
'Commodity Code
If (Details(index).innerText = "Commodity Code") And (index < DetailNo - 1) Then
Cells(rowNumber, 21) = "'" & Details(index + 1).innerText
End If
'LKZ_FDB/ CatalogID
If (Details(index).innerText = "LKZ_FDB/ CatalogID") And (index < DetailNo - 1) Then
Cells(rowNumber, 22) = Details(index + 1).innerText
End If
'Product Group
If (Details(index).innerText = "Product Group") And (index < DetailNo - 1) Then
Cells(rowNumber, 23) = Details(index + 1).innerText
End If
'Country of origin
If (Details(index).innerText = "Country of origin") And (index < DetailNo - 1) Then
Cells(rowNumber, 24) = Details(index + 1).innerText
End If
'Compliance with the substance restrictions according to RoHS directive
If (Details(index).innerText = "Compliance with the substance restrictions according to RoHS directive") And (index < DetailNo - 1) Then
Cells(rowNumber, 25) = Details(index + 1).innerText
End If
'Product class
If (Details(index).innerText = "Product class") And (index < DetailNo - 1) Then
Cells(rowNumber, 26) = Details(index + 1).innerText
End If
'Obligation Category for taking back electrical and electronic equipment after use
If (Details(index).innerText = "Obligation Category for taking back electrical and electronic equipment after use") And (index < DetailNo - 1) Then
Cells(rowNumber, 27) = Details(index + 1).innerText
End If
'Classifications
If (Details(index).innerText = "Classifications") And (index < DetailNo - 1) Then
Cells(rowNumber, 28) = Details(index + 1).innerText
End If
'Successor
If (Details(index).innerText = "Successor") And (index < DetailNo - 1) Then
Cells(rowNumber, 29) = Details(index + 1).innerText
End If
Next
End If
Next
Set xmlhttp = Nothing
Set htmldoc = Nothing
Application.StatusBar = ""
GoTo EndSub
ErrHand:
Cells(rowNumber, 3) = "Error! " & Err.Description
Application.StatusBar = ""
EndSub:
End Sub
Sub Report()
'generate a printable report worksheet
Dim rowNumber As Long
Dim rowNumberR As Long
Dim mlfbCode As String
Dim iCounter As Integer
Dim maxRow As Integer
Dim partPM, partsOK, partsAT, partsER, partsNA As Integer
partsOK = 0
partsAT = 0
partsER = 0
partsNA = 0
maxRow = 500
'--------------------------------------------
Sheets("Report").Activate
ActiveWindow.FreezePanes = False
'Clear all data in Report worksheet
Sheets("Report").Cells.Delete
DoEvents
'Write header on first row
rowNumberR = 1
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Name = "Arial"
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Size = 10
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.TintAndShade = 0
Sheets("Report").Cells(rowNumberR, 1) = "MLFB"
Sheets("Report").Cells(rowNumberR, 2) = "Product Description"
Sheets("Report").Cells(rowNumberR, 3) = "Product Lifecycle (PLM)"
Sheets("Report").Cells(rowNumberR, 4) = "Notes"
Sheets("Report").Cells(rowNumberR, 5) = "Dispatch Time"
'Format cells
Sheets("Report").Cells.VerticalAlignment = xlTop
Sheets("Report").Cells(rowNumberR, 1).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 1).EntireColumn.ColumnWidth = 18
Sheets("Report").Cells(rowNumberR, 2).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 2).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 3).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 3).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 4).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 4).EntireColumn.ColumnWidth = 20
Sheets("Report").Cells(rowNumberR, 5).EntireColumn.WrapText = True
Sheets("Report").Cells(rowNumberR, 5).EntireColumn.ColumnWidth = 8
rowNumberR = 2
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Name = "Arial"
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Size = 10
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.TintAndShade = 0
DoEvents
'--------------------------------------------
rowNumberR = 3
For rowNumber = 2 To maxRow
'Spare part availability ignored
partPM = 0
If (Sheets("Data").Cells(rowNumber, 2).Value <> "") Then
Cells(rowNumberR, 1).Select
'Spare part availability not yet established
partPM = 1
'Format cells
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Name = "Arial"
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.Size = 8
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, 1).EntireRow.Font.TintAndShade = 0
For iCounter = 1 To 5
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeBottom).LineStyle = xlContinuous
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeBottom).TintAndShade = 0
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeBottom).Weight = xlHairline
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeLeft).LineStyle = xlContinuous
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeLeft).ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeLeft).TintAndShade = 0
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeLeft).Weight = xlHairline
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeRight).LineStyle = xlContinuous
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeRight).ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeRight).TintAndShade = 0
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeRight).Weight = xlHairline
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeTop).LineStyle = xlContinuous
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeTop).ColorIndex = xlAutomatic
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeTop).TintAndShade = 0
Sheets("Report").Cells(rowNumberR, iCounter).Borders(xlEdgeTop).Weight = xlHairline
Next
mlfbCode = Sheets("Data").Cells(rowNumber, 2).Value
Sheets("Report").Cells(rowNumberR, 1) = mlfbCode
Sheets("Report").Cells(rowNumberR, 2) = Sheets("Data").Cells(rowNumber, 3).Value
Sheets("Report").Cells(rowNumberR, 3) = Sheets("Data").Cells(rowNumber, 5).Value + vbCrLf + vbCrLf + Sheets("Data").Cells(rowNumber, 6).Value
Sheets("Report").Cells(rowNumberR, 4) = Sheets("Data").Cells(rowNumber, 7).Value
Sheets("Report").Cells(rowNumberR, 5) = Sheets("Data").Cells(rowNumber, 12).Value
'PLM:
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(230, 230, 230)
sTemp = Sheets("Data").Cells(rowNumber, 5).Value
iTemp = InStr(1, sTemp, "M250", vbTextCompare)
If iTemp > 0 Then
partPM = 250
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M280", vbTextCompare)
If iTemp > 0 Then
partPM = 280
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M300", vbTextCompare)
If iTemp > 0 Then
partPM = 300
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(125, 242, 92)
End If
iTemp = InStr(1, sTemp, "M400", vbTextCompare)
If iTemp > 0 Then
partPM = 400
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(229, 242, 80)
End If
iTemp = InStr(1, sTemp, "M410", vbTextCompare)
If iTemp > 0 Then
partPM = 410
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(229, 242, 80)
End If
iTemp = InStr(1, sTemp, "M490", vbTextCompare)
If iTemp > 0 Then
partPM = 490
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(242, 135, 148)
End If
iTemp = InStr(1, sTemp, "M500", vbTextCompare)
If iTemp > 0 Then
partPM = 500
Sheets("Report").Cells(rowNumberR, 3).Interior.Color = RGB(242, 135, 148)
End If
End If
Select Case partPM
Case 250, 280, 300
partsOK = partsOK + 1
Case 400, 410
partsAT = partsAT + 1
Case 490, 500
partsER = partsER + 1
Case 1
partsNA = partsNA + 1
Case Else
'nothing to do
End Select
rowNumberR = rowNumberR + 1
DoEvents
Next
'some final formatting
Sheets("Report").Select
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeTop).LineStyle = xlContinuous
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeTop).ColorIndex = xlAutomatic
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeTop).TintAndShade = 0
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeTop).Weight = xlThin
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).LineStyle = xlContinuous
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).TintAndShade = 0
Sheets("Report").Range(Cells(1, 1), Cells(1, 5)).Borders(xlEdgeBottom).Weight = xlThick
Sheets("Report").Cells(2, 1).Value = "Active: " & CStr(partsOK)
Sheets("Report").Cells(2, 1).Interior.Color = RGB(125, 242, 92)
Sheets("Report").Cells(2, 2).Value = "PhaseOut: " & CStr(partsAT)
Sheets("Report").Cells(2, 2).Interior.Color = RGB(229, 242, 80)
Sheets("Report").Cells(2, 3).Value = "Disc.: " & CStr(partsER)
Sheets("Report").Cells(2, 3).Interior.Color = RGB(242, 135, 148)
Sheets("Report").Cells(2, 4).Value = "Other: " & CStr(partsNA)
Sheets("Report").Cells(2, 4).Interior.Color = RGB(230, 230, 230)
Sheets("Report").Cells(2, 5).Interior.Color = RGB(230, 230, 230)
DoEvents
'Format report worksheet
With Worksheets("Report").PageSetup
.PaperSize = xlPaperA4