cancel
Showing results for 
Search instead for 
Did you mean: 

Upload attachment in SAP transaction code FB03

Former Member
0 Kudos

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"

Script1.vbs:

Set Wshell = CreateObject("WScript.Shell")

Do

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!

Mike

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Mike,

You can try for example the following:

Main Macro:

. . .

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

. . .

Script1.vbs:

. . .

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

Wshell.sendkeys xclapp.cells(wscript.arguments(0),4).value

. . .

Regards,

ScriptMan

Former Member
0 Kudos

Hi Scriptman,

Im excited to test your suggestion. I already left the office. Thanks so much.

By the way, i had a mistake in my previous explanation. Path of the file is located in Activesheet.Range("E" & i).value or range E2 and it loops until all documents in column A are done.

Is your suggestion will work on that as well?

Thanks,

Mike

script_man
Active Contributor
0 Kudos

Hi Mike,

my answer is :

A = 1

B = 2

C = 3

D = 4

E = 5

etc.

Regards,

ScriptMan

Answers (0)