问题
I am trying to create folder on downloaded files(Email, PDF, Image etc..) from SAP P31 using tcode VA03. Sometimes there are multiple files in each document and it downloads only one and saved in the SAP GUI folder. It should save all the documents from each document and rename the folder with document number.
Source code:
Sub DownloadPO()
Set wshshell = CreateObject("WScript.Shell")
Set SapGuiAuto = GetObject("SAPGUI")
Set Applic = SapGuiAuto.GetScriptingEngine
Set Connection = Applic.Children(0)
Set session = Connection.Children(0)
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
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
last_row = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
po_list = Sheet1.Range("A2:A" & last_row).Value
For po = 1 To UBound(po_list)
po_number = po_list(po, 1)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/Nva03"
session.findById("wnd[0]").sendVKey 0
'session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = "75074271"
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = po_number
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").currentCellColumn = "BITM_DESCR"
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").SelectAll
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").pressToolbarButton "%ATTA_EXPORT"
session.findById("wnd[1]/tbar[0]/btn[11]").press
session.findById("wnd[1]").sendVKey 12
session.findById("wnd[0]").sendVKey 12
session.findById("wnd[0]").sendVKey 12
Next
End Sub
Excel sheet
https://drive.google.com/open?id=1W5sy8q4WH8GmtzoGUrxJ5bF_3vsbViEE
System specifications Windows : 10
Excel : 2010
VBA : 7.1
SAP : 731
来源:https://stackoverflow.com/questions/60526765/folder-creation-on-downloaded-multiple-gos-attachments-from-sap