Option Explicit
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub Add_Document()
Dim oIE As Object ' InternetExplorer.Application
Dim sURL As String
Dim UserN As Object ' MSHTML.IHTMLElement
Dim PW As Object ' MSHTML.IHTMLElement
'Dim Element As Object ' HTMLButtonElement
Dim btnInput As Object ' MSHTML.HTMLInputElement
Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
'Dim Link As Object ' MSHTML.HTMLAnchorElement
Dim ieDoc As Object 'MSHTML.HTMLDocument
Dim i As Long, j As String, k, m As String, n As String, r As Long, s As String, t, u As String, v As String, x As String, y As String
Dim sText As String, startS As String, endS As String, sMv As String
Const Agency As String = "Agency"
On Error Resume Next
Application.ScreenUpdating = False
Application.Visible = False
Select Case Application.Assistant.DoAlert("NOTICE - " & Agency, [U64].Value, msoAlertButtonOKCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbCancel
GoTo TheEnd
End Select
Kill_IE_Process 'Dong tat ca cac cua so IE
'===== VAO TRANG THEM HO SO E-MANIFEST ============
Set oIE = CreateObject("InternetExplorer.Application")
sURL = "https://e-manifest.customs.gov.vn/profile/record/list.aspx"
With oIE
.Navigate sURL
.Visible = True
apiShowWindow .hwnd, SW_MAXIMIZE
'Loop until the page finishes loading
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
End With
'===== NHAN VAO NUT CONFIRM ========================
Set ieDoc = oIE.Document
Set btnInput = ieDoc.all.Item("overridelink")
btnInput.Click
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'===== DANG NHAP ===================================
u = "ctl00$PlaceHolderMain$signInControl$"
v = "ctl00$ctl27$wPshipList$ctl00$"
x = "ctl00_ctl27_wPshipList_ctl00"
y = "__tab_" & x & "_tabDocument_"
Set UserN = ieDoc.getElementsByName(u & "UserName")
If Not UserN Is Nothing Then
UserN(0).Value = "577777777" 'UserName (thay doi phu hop)
End If
Set PW = ieDoc.getElementsByName(u & "password")
If Not PW Is Nothing Then
PW(0).Value = "password" 'Password
End If
Set btnInput = ieDoc.all.Item("ctl00_PlaceHolderMain_signInControl_login")
btnInput.Click 'Click Dang Nhap
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'====================================================
sText = ieDoc.body.innerHTML 'Lay Source code Web
startS = InStr(sText, x & "_ddlShip")
endS = InStr(sText, v & "ddlPort")
sText = Mid(sText, startS, endS - startS) 'Lay doan giua ten tau trong Source web
If InStr(UCase(sText), UCase([D6])) > 0 Then 'NEU TAU CO TRONG HE THONG E-MANIFEST
ReDo:
sURL = "https://e-manifest.customs.gov.vn/profile/record/add.aspx"
oIE.Navigate sURL
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'===== DIEN THONG TIN TAO HO SO TAU =============
For i = 1 To 8
Select Case i
'Case 1: j = v & "ddlShip": k = sRet 'Ten tau
Case 1: j = v & "ddlDocumentType": k = [E5] 'Loai ho so
Case 2: j = v & "ddlPort": k = [E8] 'Ten cang
Case 3: j = v & "txtCaption": k = UCase(Trim([D7])) 'Master name
Case 4: j = v & "txtTime": k = [E10] 'Thoi gian den/ chay
Case 5: j = v & "ddlHours": k = [D13] 'Gio
Case 6: j = v & "ddlMinutes": k = [D14] 'Phut
Case 7: j = v & "txtVoyageNumber": k = UCase(Trim([D15])) 'Voy no.
Case 8: j = v & "txtRemarks": k = UCase(Trim([D16])) 'Remarks
End Select
Set UserN = ieDoc.getElementsByName(j)
If Not UserN Is Nothing Then
UserN(0).Value = k
End If
Next i
apiShowWindow oIE.hwnd, SW_SHOWMINIMIZED
Application.Visible = True
Select Case Application.Assistant.DoAlert("FILL VSL NAME - " & Agency, [U75].Value, msoAlertButtonOKCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbOK
Case Else
GoTo TheEnd
End Select
Application.Visible = False
'===== NHAN NUT TAO HO SO TAU ===================
Set btnInput = ieDoc.all.Item(x & "_lblAdd")
btnInput.Click 'Click Dang Nhap
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'===== TAI/ UPLOAD BAN KHAI HANG HOA ============
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD GOOD DECLARATION - " & Agency, [U65].Value, msoAlertButtonOKCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbCancel
GoTo TheEnd
End Select
oIE.Visible = True
u = x & "_tabDocument_TabPanel"
Set btnInput = ieDoc.all.Item(u & "0_upFileGoodDecralation_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "0_upFileGoodDecralation_fileUpload")
btnInput.Click 'mo cua so chon file upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "0_upFileGoodDecralation_lbtnSave")
btnInput.Click 'Nhan vao nut Upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'===== TAI/ UPLOAD CARGO MANIFEST ===============
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD CARGO MANIFEST - " & Agency, [U66].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes
UploadManifest:
oIE.Visible = True
Set btnInput = ieDoc.all.Item(y & "TabPanel1")
btnInput.Click 'chuyen tab Upload BL
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'-----------------
Set btnInput = ieDoc.all.Item(u & "1_upFileHouseBill_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'-----------------
Set btnInput = ieDoc.all.Item(u & "1_upFileHouseBill_fileUpload")
btnInput.Click 'mo cua so chon file upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'-----------------
Set btnInput = ieDoc.all.Item(u & "1_upFileHouseBill_lbtnSave")
btnInput.Click 'Nhan vao nut Tai len
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
'-----------------
oIE.Visible = False
If MsgBox("Do you want to upload other Cargo Manifest?", vbOKCancel, "UPLOAD OTHER CARGO MANIFEST") = vbOK Then GoTo UploadManifest
Case vbCancel
GoTo TheEnd
End Select
'===== TAI/ UPLOAD BAN KHAI CHUNG ================
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD GENERAL DECLARATION - " & Agency, [U67].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes
oIE.Visible = True
Set btnInput = ieDoc.all.Item(y & "TabPanel2")
btnInput.Click 'chuyen tab Upload Bkc
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "2_upFileGeneralDecralation_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "2_upFileGeneralDecralation_fileUpload")
btnInput.Click 'mo cua so chon file upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "2_upFileGeneralDecralation_lbtnSave")
btnInput.Click 'Nhan vao nut Upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Case vbCancel
GoTo TheEnd
End Select
'===== TAI/ UPLOAD CREW LIST =====================
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD CREW LIST - " & Agency, [U68].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes
oIE.Visible = True
Set btnInput = ieDoc.all.Item(y & "TabPanel3")
btnInput.Click 'chuyen tab Upload Crew List
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "3_upFileCrew_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "3_upFileCrew_fileUpload")
btnInput.Click 'mo cua so chon file upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "3_upFileCrew_lbtnSave")
btnInput.Click 'Nhan vao nut Upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Case vbCancel
GoTo TheEnd
End Select
'===== TAI/ UPLOAD CREW 'S EFFECT ================
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD CREW 'S EFFECT DECLARATION - " & Agency, [U69].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes
oIE.Visible = True
Set btnInput = ieDoc.all.Item(y & "TabPanel4")
btnInput.Click 'chuyen tab Upload Bkc
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "4_upFileCrewEffect_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "4_upFileCrewEffect_fileUpload")
btnInput.Click 'mo cua so chon file upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "4_upFileCrewEffect_lbtnSave")
btnInput.Click 'Nhan vao nut Upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Case vbCancel
GoTo TheEnd
End Select
'===== TAI/ UPLOAD SHIP 'S STORE =================
oIE.Visible = False
Select Case Application.Assistant.DoAlert("UPLOAD SHIP 'S STORE DECLARATION - " & Agency, [U70].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes
oIE.Visible = True
Set btnInput = ieDoc.all.Item(y & "TabPanel5")
btnInput.Click 'chuyen tab Upload Bkc
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "5_upFileShipStore_rdnStatus_1")
btnInput.Click 'chon nut thay doi
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "5_upFileShipStore_fileUpload")
btnInput.Click 'mo cua so Upload ban khai hang hoa
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Set btnInput = ieDoc.all.Item(u & "5_upFileShipStore_lbtnSave")
btnInput.Click 'Nhan vao nut Upload
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Case vbCancel
GoTo TheEnd
End Select
oIE.Visible = False
Application.Visible = True
Select Case Application.Assistant.DoAlert("NOTICE - " & Agency, [U71].Value, msoAlertButtonOK, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
End Select
'***** NEU TAU CHUA CO TRONG HE THONG => TAO TAU MOI *****
Else
Application.Visible = False
sURL = "https://e-manifest.customs.gov.vn/profile/ship/add.aspx"
oIE.Navigate sURL
oIE.Visible = False
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Select Case Application.Assistant.DoAlert("CREAT NEW VESSEL - " & Agency, [U72].Value, msoAlertButtonYesNoCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbYes 'Tao tau tu dong tren web
For k = 1 To 15
Select Case k
Case 1: j = v & "txtName": m = "VESSEL 'S NAME?": n = "NHAP TEN TAU": s = Trim([D6]): t = 2
Case 2: j = v & "txtIMO": m = "IMO NUMBER?": n = sMv & "IMO NUMBER": s = "[IMO No.]": t = 1
Case 3: j = v & "txtCall": m = "CALL SIGN?": n = sMv & "HO HIEU": s = "[Call sign]": t = 2
Case 4: j = v & "txtRegisterNumber": m = "REGISTED NUMBER?": n = sMv & "SO DANG KY": s = "[Register No.]": t = 2
Case 5: j = v & "txtFishing": m = "REGISTED NUMBER (fishing boat)?": n = sMv & "SO DANG KY TAU CA": s = s: t = 2
Case 6: j = v & "txtDate": m = "DATE OF REGISTRATION (DD/MM/YYYY)?": n = sMv & "REGISTED DATE": s = "DD/MM/YYYY": t = 2
Case 7: j = v & "txtNetTonnage": m = "NET TONNAGE?": n = sMv & "TRONG TAI THUAN": s = "[NRT]": t = 1
Case 8: j = v & "txtNet": m = "NRT (fishing boat)?": n = sMv & "TRONG TAI THUAN TAU CA": s = s: t = 1
Case 9: j = v & "txtGross": m = "GROSS TONNAGE?": n = sMv & "TONG DUNG TICH": s = "[GRT]": t = 1
Case 10: j = v & "txtGrossTonnage": m = "GRT (fishing boat)": n = sMv & "TONG DUNG TICH TAU CA": s = s: t = 1
Case 11: j = v & "txtWeightTonnage": m = "DEAD WEIGHT?": n = sMv & "TRONG TAI": s = "[DWT]": t = 1
Case 12: j = v & "txtLOA": m = "LOA?": n = sMv & "CHIEU DAI LON NHAT": s = "[LOA]": t = 1
Case 13: j = v & "txtBreadth": m = "BREATH?": n = sMv & "CHIEU RONG": s = "[Chieu rong]": t = 1
Case 14: j = v & "txtSailingSpeed": m = "VESSEL 'S SPEED?": n = sMv & "TOC DO": s = 12: t = 2
Case 15: j = v & "txtRemarks": m = "REMARKS": n = sMv & "GHI CHU": s = "": t = 2
End Select
Set UserN = ieDoc.getElementsByName(j)
If Not UserN Is Nothing Then
UserN(0).Value = UCase(Application.InputBox(m, n, s, , , , , t))
If k = 1 Then sMv = "MV. " & UserN(0).Value & " - "
If k = 4 Or k = 7 Or k = 9 Then
s = UserN(0).Value
End If
End If
Next k
Set UserN = ieDoc.getElementsByName(v & "ddlProcessType")
If Not UserN Is Nothing Then
UserN(0).Value = 9 '9 = Registration ; 5 = Correction ; 1 = Cancellation
End If
Set UserN = ieDoc.getElementsByName(v & "ddDanhSachHangTau")
If Not UserN Is Nothing Then
UserN(0).Value = 217 '217 = CTY CP DLHH VINACOMIN
End If
Set ElementCol = ieDoc.getElementsByTagName("input")
For Each btnInput In ElementCol
If btnInput.ID = x & "_chkSubmitTo_0" Or btnInput.ID = x & "_chkSubmitTo_1" Or btnInput.ID = x & "_chkSubmitTo_2" Then
btnInput.Click
End If
Next
oIE.Visible = True
Application.Visible = True
Do While oIE.LocationURL = sURL
Select Case Application.Assistant.DoAlert("CREAT NEW VESSEL - " & Agency, [U73].Value, msoAlertButtonOKCancel, msoAlertIconInfo, msoAlertDefaultFirst, msoAlertCancelFirst, False)
Case vbOK
Set btnInput = ieDoc.all.Item(x & "_lblAdd")
btnInput.Click 'Nhan vao nut Tai len
oIE.Visible = True
Do While oIE.Busy Or oIE.ReadyState <> 4: DoEvents: Loop
Case vbCancel
GoTo TheEnd
End Select
Loop
GoTo ReDo 'Luu tau moi va quay lai tao ho so E-Manifest
Case vbCancel
Kill_IE_Process
End Select 'Ket thuc truong hop tao tau moi
End If
TheEnd:
oIE.Visible = True
Set oIE = Nothing
Set ieDoc = Nothing
Set UserN = Nothing
Set PW = Nothing
Set btnInput = Nothing
Set ElementCol = Nothing
Application.Visible = True
Application.ScreenUpdating = True
End Sub