Skip to Content
Former Member
Jun 09, 2016 at 03:00 PM

Upload attachment in SAP transaction code FB03


Hi Script Gurus,

I am currently trying to automate attaching of pdf copies of invoices to FB03. I am almost done with my code but having problem with the separate vbs (Script1.vbs) i created.

ActiveSheet.Range("D" & i).Value is the path of the file that i want to upload but since i have a lot of invoices to attach, i want the script to capture what is in the column D. But when i try below code, i am encountering error Object required:'Activesheet'. i tried putting Dim Activesheet but not successful.

if i specify the path and put Wshell.sendkeys "1234.pdf", its working. Please help.

Below are my codes.

Main Macro:

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

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

Do While ActiveSheet.Range("B" & i) <> ""

session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = ActiveSheet.Range("B" & i).Value 'docnumber

session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = ActiveSheet.Range("C" & i).Value 'companycode

session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = ActiveSheet.Range("D" & i).Value 'year

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

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

session.findById("wnd[0]/shellcont/shell").pressContextButton "CREATE_ATTA"

Set WShell = CreateObject("WScript.Shell")

WShell.Run "C:\Users\" & Format(Environ("USERNAME"), ">") & "\Desktop\Script1.vbs", 1, False

session.findById("wnd[0]/shellcont/shell").SelectContextMenuItem "PCATTA_CREA"


Set Wshell = CreateObject("WScript.Shell")


bWindowFound = Wshell.AppActivate("Import file")

WScript.Sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Import file")

if (bWindowFound) Then

Wshell.appActivate "Import file"

WScript.Sleep 100

Wshell.sendkeys "{ENTER}"

WScript.Sleep 100

Wshell.sendkeys ActiveSheet.Range("D" & i).Value

WScript.Sleep 100

Wshell.sendkeys "{ENTER}"

WScript.Sleep 100

end If

Thank you in advance!