Skip to Content
avatar image
Former Member

Attaching documents in VA03/Va02 via Script

Hi,

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]").maximize

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"

session.findById("wnd[0]/tbar[0]/btn[3]").press

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

Next

MsgBox "Processamento Finalizado"

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Aug 03, 2017 at 01:14 PM

    Hi Fabiana,

    pleace uncheck the "Show native MS Windows dialogs" option in the SAPGUI Options, then can you record the path and the name of the file.

    For it to work at the end, the name must be fetched from the second column.

    for example:

    COL2 = Trim(CStr(objSheet.Cells(i, 2).Value))

    and

    session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
    session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_PCATTA_CREA"
    session.findById("wnd[1]/usr/ctxtDY_PATH").text = "c:\tmp"
    session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = COL2
    session.findById("wnd[1]/tbar[0]/btn[0]").press

    session.findById("wnd[0]/tbar[0]/btn[3]").press

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

    Regards,

    ScriptMan

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 10, 2017 at 01:21 PM

    Hi Script Man,

    The problem is that in our SAP there is no option to disable this option. Is there another solution?

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 23, 2017 at 11:56 AM

    Hi Fabiana,

    please have a look at the following link:

    https://archive.sap.com/discussions/thread/1799453

    Regards,

    ScriptMan

    Add comment
    10|10000 characters needed characters exceeded