Skip to Content
Former Member
Aug 03, 2017 at 09:06 AM

Attaching documents in VA03/Va02 via Script



We need to attach messages from Outlook to SAP orders, and I was tempted to create a script to automate this. We know the path name and the filename of the attachment, but we still have to manually find the document in the browse window and confirm it. Is it possible to have the script attach a given SAP document directly in the script with no user interaction?

We are using VBA scripting in Excel for these scripts.

The problem is that when we write a script, it does not recognize the "Import file"

My Script is:

If Not IsObject(Application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set Application =SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

Set Connection = Application.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

Dim objExcel

Dim objSheet, intRow, i

Dim quantidade, linha, pg

Dim deliveryatual, deliveryultima, itematual, itemproximo

Set objExcel = GetObject(, "Excel.Application")

Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 1 To objSheet.UsedRange.Rows.Count COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1 deliveryatual = COL1

If deliveryultima <> deliveryatual Then


session.findById("wnd[0]/tbar[0]/okcd").Text = "/nva02"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = COL1

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]").sendVKey 0

deliveryultima = deliveryatual

End If

session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"

session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_PCATTA_CREA"


objExcel.Cells(i, 2).Value = "OK"

'msgbox Trim(CStr(objSheet.Cells(i+1, 1).Value))

'msgbox Trim(CStr(objSheet.Cells(1, 1).Value))

If Trim(CStr(objSheet.Cells(i + 1, 1).Value)) <> Trim(CStr(objSheet.Cells(i, 1).Value)) Then

End If


MsgBox "Processamento Finalizado"