ption Explicit
Public wbk1 As Workbook, wbk2 As Workbook, ws1 As Worksheet, ws2 As Worksheet
Public cVis As Range '''copy_from, copy_to As Range
Sub sample_JBA()
'''dodaje sample do JBA, zamiast wpisywania do 10/OE2 JBAP
Dim lOstatniWiersz, lOWiersz As Long, licznik As Long, n As Long, błąd As Long, poprawny As Long
Dim popraw, niepoprawna As String, sesja As String, zczytuj As String, zczytuj2 As String, wynik As String
If bZłyWiersz = True Or bZłaKolumna = True Then
popraw = MsgBox("Zaznacz dane w kolumnie A i wybierz wiersz/wiersze w obrębie zakresu danych, poza wierszami 1 i 2.", _
vbOKOnly + vbInformation, "Zły wybór")
Exit Sub
Else
'''najpierw sprawdzam, czy mamy poprawne dane w zaznaczonym zakresie, dopiero potem
'''nastąpi wprowadzanie danych do JBA
For Each cVis In Selection
If cVis.Value = "" Or cVis.Offset(0, 5).Value = "" Or cVis.Offset(0, 5).Value = 0 Then
popraw = MsgBox("W wierszu nr " & cVis.Row & " znaleziono puste komórki lub wartość zerową." _
& Chr(13) & "Wprowadź nr katalogowy w kolumnie A i ilość sztuk w kolumnie F.", vbOKOnly + _
vbCritical, "Brak danych lub niepoprawne dane")
Exit Sub
End If
If Not IsNumeric(cVis.Offset(0, 5).Value) Then
popraw = MsgBox("W wierszu nr " & cVis.Row & " wprowadzono wartość nie numeryczną w kolumnie F.", _
vbOKOnly + vbCritical, "Niepoprawne dane")
Exit Sub
End If
Next cVis
'Set wbk1 = Workbooks("CEO WEEKLY SHIPMENTS")
Set ws1 = Sheets("shipments")
If ws1.FilterMode = True Then ws1.ShowAllData
'''ustalenie rodzaju kompanii i sesji JBA
sesja = [C1] '''oznaczenie sesji w lokalnym JBA
Dim SO As String
Dim ps, ia
Set ps = CreateObject("PCOMM.autECLPS")
Set ia = CreateObject("PCOMM.autECLOIA")
ps.SetConnectionByName (sesja)
ia.SetConnectionByName (sesja)
ps.autECLFieldList.Refresh
ia.WaitForInputReady (2000)
zczytuj = ps.GetTextRect(1, 16, 1, 17)
If zczytuj = "P9" Then
popraw = MsgBox("Przeloguj się do lokalnego JBA (88) i ponownie uruchom makro", _
vbOKOnly + vbCritical, "Niewłaściwa kompania JBA")
Exit Sub
End If
zczytuj2 = ps.GetTextRect(1, 18, 1, 19)
If zczytuj2 = "88" Then
If Trim(ps.autECLFieldList(1).GetText) <> "AM0V" Then
popraw = MsgBox("Wróć do ekranu głównego i ponownie uruchom makro", _
vbOKOnly + vbCritical, "Niewłaściwy ekran w JBAP")
Exit Sub
End If
Else
popraw = MsgBox("Nie znaleziono sesji określonej w komórce C1." & Chr(13) & _
"Zaloguj się do lokalnego JBA (88), sprawdź wybraną sesję i ponownie uruchom makro.", _
vbOKOnly + vbCritical, "Błąd")
Exit Sub
End If
'''wprowadzanie danych do 10/OE2 JBAP
AppActivate "Session " + sesja
ps.SendKeys "10/OE2", 21, 11
ia.WaitForInputReady (2000)
ps.SendKeys "[enter]"
For Each cVis In Selection
'licznik = licznik + 1
n = 0
zawróć:
ia.WaitForInputReady (2000)
n = n + 1
If n = 2000 Then
popraw = MsgBox("Makro wpadło w pętlę w skutek błędu JBA i zatrzymało się przy itemie z wiersza nr " & _
cVis.Row & ".", vbOKOnly + vbCritical, "Błąd JBA")
cVis.Font.Color = -16776961
Exit Sub
End If
If ps.GetTextRect(2, 19, 2, 37) <> "Add samples for CEO" Then GoTo zawróć
ps.SendKeys cVis.Value, 4, 14
ia.WaitForInputReady (2000)
ps.SendKeys "[enter]"
ia.WaitForInputReady (2000)
If ps.GetTextRect(17, 5, 17, 33) = "Item not exist in Parts file." Then
ps.SendKeys "[pf8]"
End If
n = 0
zawracaj:
ia.WaitForInputReady (4000)
n = n + 1
If n = 2000 Then
popraw = MsgBox("Makro wpadło w pętlę w skutek błędu JBA i zatrzymało się przy itemie z wiersza nr " & _
cVis.Row & ".", vbOKOnly + vbCritical, "Błąd JBA")
cVis.Font.Color = -16776961
Exit Sub
End If
If ps.GetTextRect(7, 5, 7, 24) <> "Add samples for CEO?" Then GoTo zawracaj
ps.SendKeys "Y", 7, 26
ia.WaitForInputReady (2000)
ps.SendKeys " ", 10, 37
ia.WaitForInputReady (2000)
Select Case cVis.Offset(0, 5).Value
Case cVis.Offset(0, 5).Value = 1 To 9
ps.SendKeys cVis.Offset(0, 5).Value, 10, 39
ia.WaitForInputReady (2000)
Case cVis.Offset(0, 5).Value = 10 To 10
ps.SendKeys cVis.Offset(0, 5).Value, 10, 38
ia.WaitForInputReady (2000)
End Select
ps.SendKeys "[pf8]"
n = 0
powróć:
ia.WaitForInputReady (4000)
'''poniższy if dodany, bo w testowym JBA pojawił się taki błąd - w live chyba to jednak nie występuje
If ps.GetTextRect(14, 5, 14, 28) = "Error: item not updated." Then
cVis.Font.Color = -16776961
popraw = MsgBox("Makro napotkało błąd JBA i dla itemu z wiersza numer " & cVis.Row & _
" nie mogło zarequestować sampli dla CEO." & Chr(13) & _
"Naciśnij OK w celu kontynuowania dodawania sampli dla pozostałych itemów.", _
vbOKOnly + vbInformation, "Błąd JBA")
ps.SendKeys "[pf12]"
ia.WaitForInputReady (4000)
błąd = błąd + 1
ElseIf ps.GetTextRect(14, 5, 14, 30) = "Item updated successfully." Then
poprawny = poprawny + 1
ElseIf ps.GetTextRect(17, 5, 17, 51) = "Samples have already produced for this FG item." Then
popraw = MsgBox("JBA wykrył, że sample w ilości " & ps.GetTextRect(8, 35, 8, 36) & _
" sztuk zostały już zarequestowane dla itemu z wiersza numer " & cVis.Row & "." & Chr(13) & Chr(13) & _
"Czy chcesz ponownie dodać sample?", vbYesNo + vbQuestion, "Sample już zarequestowane")
Select Case popraw
Case Is = 6 '''YES
ps.SendKeys "[pf8]"
ia.WaitForInputReady (4000)
poprawny = poprawny + 1
Case Is = 7 '''NO
ps.SendKeys "[pf12]"
ia.WaitForInputReady (4000)
ps.SendKeys "[pf12]"
ia.WaitForInputReady (4000)
'cVis.Font.Color = -16776961
End Select
Else
popraw = MsgBox("Makro wpadło w pętlę w skutek błędu JBA i zatrzymało się przy itemie z wiersza nr " & _
cVis.Row & ".", vbOKOnly + vbCritical, "Błąd JBA")
cVis.Font.Color = -16776961
Exit Sub
End If
n = n + 1
If n = 2000 Then
popraw = MsgBox("Makro wpadło w pętlę w skutek błędu JBA i zatrzymało się przy itemie z wiersza nr " & _
cVis.Row & ".", vbOKOnly + vbCritical, "Błąd JBA")
cVis.Font.Color = -16776961
Exit Sub
End If
If ps.GetTextRect(4, 14, 4, 28) <> " " Then GoTo powróć
Next cVis
ps.SendKeys "[pf3]"
Select Case poprawny
Case Is = 0
wynik = MsgBox _
("Wystąpił błąd JBA lub zrezygnowano z requestowania sampli i w rezultacie makro nie dodało sampli dla żadnego itemu." _
, vbOKOnly + vbInformation, "Wynik")
Case Is = 1
Select Case błąd
Case Is = 0
wynik = MsgBox("Zarequestowano sample dla 1 zaznaczonego itemu.", vbOKOnly + _
vbInformation, "Wynik")
Case Is = 1
wynik = MsgBox("Zarequestowano sample dla 1 itemu." & Chr(13) & _
"Dla itemu zaznaczonego na czerwono nie udało się zarequestować sampli.", _
vbOKOnly + vbInformation, "Wynik")
Case Is > 1
wynik = MsgBox("Zarequestowano sample dla 1 itemu." & Chr(13) & _
"Dla itemów zaznaczonych na czerwono nie udało się zarequestować sampli.", _
vbOKOnly + vbInformation, "Wynik")
End Select
Case Is > 1
Select Case błąd
Case Is = 0
wynik = MsgBox("Zarequestowano sample dla " & poprawny & " zaznaczonych itemów.", vbOKOnly _
+ vbInformation, "Wynik")
Case Is = 1
wynik = MsgBox("Zarequestowano sample dla " & poprawny & " zaznaczonych itemów." & Chr(13) & _
"Dla itemu zaznaczonego na czerwono nie udało się zarequestować sampli.", _
vbOKOnly + vbInformation, "Wynik")
Case Is > 1
wynik = MsgBox("Zarequestowano sample dla " & poprawny & " zaznaczonych itemów." & Chr(13) & _
"Dla itemów zaznaczonych na czerwono nie udało się zarequestować sampli.", _
vbOKOnly + vbInformation, "Wynik")
End Select
End Select
End If
End Sub