on 06-09-2016 4:00 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.