Nhờ các anh chị kiểm tra dùm e code e sai chỗ nào mà vẫn báo lỗi "Run time error '424'"

Liên hệ QC

tdnhandno

Thành viên mới
Tham gia
10/3/16
Bài viết
47
Được thích
1
Sub testthu()
Dim i As Long, EndR As Long
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Applications = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Applications.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
EndR = Sheet1.Range("A65000").End(xlUp).Row

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "0000000259"
For i = 2 To EndR
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-ZF_MST").Text = Sheet1.Range("A" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/txtZTB_HSMG_H-SO_HS").Text = Sheet1.Range("B" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_HS").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/txtZTB_HSMG_H-SO_CVAN").Text = "01"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_CVAN").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_DU_HS").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").Text = "20"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").SetFocus
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").caretPosition = 2
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressToolbarButton "CREATE"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressToolbarButton "CREATE"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_TIEU_MUC", "1701"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_CHUONG", "757"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_KY_THUE_TU", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_KY_THUE_DEN", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_THUE_DNMG", Sheet1.Range("I" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_MA_LYDO", "2001"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_TIEU_MUC", "1003"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_CHUONG", "757"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_KY_THUE_TU", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_KY_THUE_DEN", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_THUE_DNMG", Sheet1.Range("K" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_MA_LYDO", "2001"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").setCurrentCell 1, "ZF_MA_LYDO"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressEnter
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3").Select
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").Text = Sheet1.Range("P" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/ctxtZTB_HSMG_H-ZZ_NGAY_QD").Text = "06052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").SetFocus
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").caretPosition = 4
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/btnBTN_HOTRO").press
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").modifyCell 0, "ZF_THUE_DU_DKMG", Sheet1.Range("N" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").modifyCell 1, "ZF_THUE_DU_DKMG", Sheet1.Range("O" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").pressEnter
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
Next i
End Sub
 
Sub testthu()
Dim i As Long, EndR As Long
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Applications = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = Applications.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
EndR = Sheet1.Range("A65000").End(xlUp).Row

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "0000000259"
For i = 2 To EndR
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-ZF_MST").Text = Sheet1.Range("A" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/txtZTB_HSMG_H-SO_HS").Text = Sheet1.Range("B" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_HS").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/txtZTB_HSMG_H-SO_CVAN").Text = "01"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_CVAN").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-NGAY_DU_HS").Text = "05052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").Text = "20"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").SetFocus
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/ctxtZTB_HSMG_H-TRG_HOP_MG").caretPosition = 2
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressToolbarButton "CREATE"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressToolbarButton "CREATE"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_TIEU_MUC", "1701"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_CHUONG", "757"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_KY_THUE_TU", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_KY_THUE_DEN", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_THUE_DNMG", Sheet1.Range("I" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 0, "ZF_MA_LYDO", "2001"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_TIEU_MUC", "1003"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_CHUONG", "757"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_KY_THUE_TU", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_KY_THUE_DEN", "2005"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_THUE_DNMG", Sheet1.Range("K" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").modifyCell 1, "ZF_MA_LYDO", "2001"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").setCurrentCell 1, "ZF_MA_LYDO"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC1/ssubHSMG_SCA:ZPG_MG_HS:0201/cntlDNMG/shellcont/shell").pressEnter
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3").Select
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").Text = Sheet1.Range("P" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/ctxtZTB_HSMG_H-ZZ_NGAY_QD").Text = "06052020"
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").SetFocus
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/txtZTB_HSMG_H-ZZ_SO_QD").caretPosition = 4
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/btnBTN_HOTRO").press
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").modifyCell 0, "ZF_THUE_DU_DKMG", Sheet1.Range("N" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").modifyCell 1, "ZF_THUE_DU_DKMG", Sheet1.Range("O" & i).Value
session.findById("wnd[0]/usr/tabsHSMG/tabpHSMG_FC3/ssubHSMG_SCA:ZPG_MG_HS:0203/cntlDXMG/shellcont/shell").pressEnter
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
Next i
End Sub
Bạn cần phải tìm người viết code để hỏi mới được. Dám cá là GPE không có người tìm ra nguyên nhân tại sao lại bị lỗi. Có ai cá cược không?
 
Upvote 0
Upvote 0
Bạn ở đây lâu rồi, và biết dùng VBA đủ để biết phải nói rõ lỗi xảy ra ở dòng nào chứ.
Cái tin tức quan trọng nhất, và sẵn trước mặt mà bạn bỏ qua, bắt người ta phải mò giùm sao?
 
Upvote 0
Bạn ở đây lâu rồi, và biết dùng VBA đủ để biết phải nói rõ lỗi xảy ra ở dòng nào chứ.
Cái tin tức quan trọng nhất, và sẵn trước mặt mà bạn bỏ qua, bắt người ta phải mò giùm sao?
Set Connection = Applications.Children(0) dạ ở dòng này. Nhưng e nghĩ mãi ko hiểu sao lại lỗi ở đây a ạ
 
Upvote 0
Vậy bạn hiểu nó là gì không?
 
Upvote 0
Người nào viết cái code ban đầu khong có kinh nghiệm đặt tên biến.
Cái SAP Application nên đặt tên nó rõ rệt là SAP_App, hay SAP_Application
Người không kinh nghiệm kia đã dùng Applications cho nên dễ bị lẫn lộn.
Trong nhóm code này:
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set Applications = SapGuiAuto.GetScriptingEngine
End If
Application là Excel, và nó là object. Vì vậy nhóm code trên không được thực hiện.
Cái 'Applications' trên không hề được set làm object gì cả.
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom