on 08-24-2020 10:34 AM
This is my code i find somewhere on internet and i paste script in Excel vba, connect it with button and it works great.
Now i nead to updat it so i can input date from Excel cell. Please help me how to change: 24.08.2020 with Excel input?
I nead this because sometimes the data for one Day is Just not enought. So i will Have in Excel function =TODAY()+K7. This way if i input 1 in K7 cell, i will get data for 2 days and if i input 2 i will get data for 3 days. Please help me i am noob here. 🙂 tnx
Code:
Private Sub CommandButton1_Click()
On Error GoTo Err_NoSAP
If Not IsObject(SAPGuiApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPGuiApp.Children(0)
End If
If Not IsObject(SAP_session) Then
Set SAP_session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject SAP_session, "on"
WScript.ConnectObject SAPGuiApp, "on"
End If
If (Connection.Children.Count > 1) Then GoTo Err_TooManySAP
Set aw = SAP_session.ActiveWindow()
aw.findById("wnd[0]").maximize
On Error GoTo Err_Description
SAP_session.findById("wnd[0]").maximize
SAP_session.findById("wnd[0]/usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell").doubleClickNode "F00034"
SAP_session.findById("wnd[0]/tbar[1]/btn[17]").press
SAP_session.findById("wnd[1]/usr/txtV-LOW").Text = "KA"
SAP_session.findById("wnd[1]/usr/txtENAME-LOW").Text = ""
SAP_session.findById("wnd[1]/usr/txtV-LOW").caretPosition = 2
SAP_session.findById("wnd[1]/tbar[0]/btn[8]").press
SAP_session.findById("wnd[0]/usr/chkTR1").Selected = True
SAP_session.findById("wnd[0]/usr/chkTR3").Selected = True
SAP_session.findById("wnd[0]/usr/chkTR3").SetFocus
SAP_session.findById("wnd[0]").sendVKey 2
SAP_session.findById("wnd[0]/usr/chkTR4").Selected = True
SAP_session.findById("wnd[0]/usr/ctxtDATUM_OD").SetFocus
SAP_session.findById("wnd[0]/usr/ctxtDATUM_OD").caretPosition = 0
SAP_session.findById("wnd[0]").sendVKey 4
SAP_session.findById("wnd[1]/usr/btnPUSHB_PICK").press
SAP_session.findById("wnd[0]/usr/ctxtDATUM_DO").Text = "24.08.2020"
SAP_session.findById("wnd[0]/usr/ctxtDATUM_DO").SetFocus
SAP_session.findById("wnd[0]/usr/ctxtDATUM_DO").caretPosition = 10
SAP_session.findById("wnd[0]/tbar[1]/btn[8]").press
SAP_session.findById("wnd[0]/tbar[1]/btn[45]").press
SAP_session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").Select
SAP_session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").SetFocus
SAP_session.findById("wnd[1]/tbar[0]/btn[0]").press
SAP_session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "C:\Users\zspka\Desktop"
SAP_session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "Plan danes.xls"
SAP_session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 14
SAP_session.findById("wnd[1]/tbar[0]/btn[11]").press
SAP_session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
Exit Sub
Err_Description:
MsgBox ("The program has generated an error;" & Chr(13) & _
"the reason for this error is unknown."), vbInformation, _
"For Information..."
Exit Sub
Err_NoSAP:
MsgBox ("You don't have SAP open or " & Chr(13) & _
"scripting has been disabled."), vbInformation, _
"For Information..."
Exit Sub
Err_TooManySAP:
MsgBox ("You must only have one SAP session open. " & Chr(13) & _
"Please close all other open SAP sessions."), vbInformation, _
"For Information..."
Exit Sub
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.