Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems Sending a Number with Excel VBA to SAP

Status
Not open for further replies.

BeckyMc

Technical User
Jun 19, 2001
51
US

This might be more of an SAP question than a VBA question but I'm not having a lot of luck finding a good SAP forum that's easy to use and working well. I'm trying to use the following code to write to an SAP screen and eventually print the data that it finds. The code is working well down to the line that says

session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:pPIO_ENTRY:1200/ctxtS_KDAUF-LOW").Text = Cell1Val

Then I get an error message about an invalid argument. The suggestions was that because I've been sending a very large number that I should be sending text but when you look at the properties of the field in question in SAP you see comparison operators for numbers so I think it is pretty much a numeric field.

The message I'm getting says it's an invalid data type. One of the values I'm trying to send is 150195919 so I've tried sending it as integer, long or double and all types give same error. I've tried sending the data over as a string variable or by concatenating chr(34) to the variable Cell1Val and get the same error.

When the code dies and I go to look the SAP screen that the code is trying to change I see the term "activesheet" in one of the cells it's trying to change. I don't know why. I did refer to activesheet once instead of sheets("sheet1") but not for a several tries. Is there a cache somewhere that I need to clear? That's never happened to us when using these screens manually.

I'm not sure if that's why I'm getting an error or of this line of code is still wrong.
============================================


Code:
Sub GetData()

Dim I As Integer
Dim HowMany As Double
Dim Cell1Val As Long
Dim Cell2Val As Long

Dim App, Connection, session As Object
'
  Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
  Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
  Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently onnected
  Set session = SAPCon.Children(0)
'
'session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = 360"
'session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "(username)"
'session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "(password)"
'session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = ""

HowMany = InputBox("How many items are there?")

I = 2

Do While I < HowMany + 2

    Cell1Val = Sheets("sheet1").Cells(I, 2).Value
    Cell2Val = Cells(I, 3).Value
        MsgBox Cell1Val

    
'    If IsObject(WScript) Then
'   WScript.ConnectObject session, "on"
'   WScript.ConnectObject Application, "on"
'End If
'session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/ncoois"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ssub%_SUBSCREEN_TOPBLOCK:PPIO_ENTRY:1100/ctxtPPIO_ENTRY_SC1100-ALV_VARIANT").Text = "/SP00000US37"
session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_KDAUF-LOW").SetFocus
session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_KDAUF-LOW").caretPosition = 0
session.findById("wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/btn%_S_KDAUF_%_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/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/btn%_S_KDPOS_%_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/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_KDAUF-LOW").Text = Cell1Val
session.findById("wnd[0]/tbar[1]/btn[8]").press

    
    I = I + 1
Loop

MsgBox "Done looping"


End Sub


[code]
 
Tried that unfortunately and it didn't work. Thanks

 
We're thinking a file upload approach would be better than an individual upload....I just haven't done that yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top