# SAP Automation with Excel VBA



## NinoD (Oct 7, 2022)

Hi All,

I am working on my SAP automation process. I have written most of it but I am struggling with writing code for copying dates from two different rows to  Posting date : "from" and "to". 

LastRow = sht.Range("D2").CurrentRegion.Rows.Count
sht.Range("D2").Copy

Session.FindById("wnd[0]").ResizeWorkingPane 68, 23, False
Session.FindById("wnd[0]/usr/btn%_SO_BUDAT_%_APP_%-VALU_PUSH").Press
Session.FindById("wnd[1]/tbar[0]/btn[24]").Press
Session.FindById("wnd[1]/tbar[0]/btn[8]").Press
Session.FindById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").SetFocus
Session.FindById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").CaretPosition

I used this code to copy date to "From" but unfortunately I am not able to do the same for "to".

I would appreciate if anybody knows any solution for this 

Best Regards,
Nino


----------



## sanantonio (Dec 23, 2022)

Hi.

Not a great solution but does your version of SAP have the "record" function? That way just record yourself typing in a "To" date in the relevant box. Open the script in Notepad and all the code will appear that you recorded?

I do all of my SAP coding in the same way as I've found our company's SAP version has a lot of company specific transactions built which means the coding is rarely translatable across transactions.


```
session.findById("wnd[0]/usr/ctxtSO_LDAT-LOW").Text = "Sheet5.Range("H1")"
session.findById("wnd[0]/tbar[1]/btn[8]").press
```

I just checked a macro I have and this is entering a "to" date. Not sure if that helps :-/


----------

