cancel
Showing results for 
Search instead for 
Did you mean: 

Import date from Excel cell

0 Kudos

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

former_member30
Community Manager
Community Manager

Hi and welcome to the SAP Community!

Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members. For example, you can outline what steps you took to find answers (and why they weren't helpful) and share screenshots of what you've seen/done. The more details you provide, the more likely it is that members will be able to assist you.

Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment).

Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

Cheers,
Julia
SAP Community Moderator

0 Kudos

I find solution :

Format(Now()+1,"dd.mm.yyyy")



SAP_session.findById("wnd[0]/usr/ctxtDATUM_DO").Text = Format(Now()+1,"dd.mm.yyyy")


This work great 
0 Kudos

Solution is :

SAP_session.findById("wnd[0]/usr/ctxtDATUM_DO").Text = Format(Now()+1,"dd.mm.yyyy")

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Aditional material