cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Attaching document via script

0 Likes
4,244

Related to my last question...

We attach scanned images to many of our SAP documents via a script.  We know the path name and the filename of the attachment, but we still have to manually find the document in a browse window and confirm it.  Is it possible to have the script attach the scanned image to a given SAP document directly in the script with no user interaction?

Also, is it possible to download all the attachments from a given SAP document to our file server without user interaction?

We are using VBA scripting in Excel for these scripts.

Thanks,

Tyler

View Entire Topic
Former Member
0 Likes

Hi I am trying this code as per my requirement which is attaching the doc to material number.

but it is not working .Please help

The Material has been successfully read from the input file but not attaching the document.

When the main file runs it goes to the import screen and wait for the file to be selected manually.

But if we select then it throws error

line      54

char      5

error    " object required "

code    800A01a8

Source Microsoft VB script runtime error

My Main file code is

   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

Const TristateFalse = 0

Const ForReading = 1

Const FILE_NAME = "C:\Temp\OrderScanNM.txt"

Dim FSO

Dim objStream

Dim objFile

'--------------------

Dim OrdNum

Dim FileName

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FileExists(FILE_NAME) Then

         Set objStream = FSO.OpenTextFile(FILE_NAME, _

             ForReading, False, TristateFalse)

        Do While Not objStream.AtEndOfStream

             strLine = objStream.ReadLine

             tx = Left(strLine,8)

             If tx = " " Then

                OrdNum = Left(strLine,7)

                FileName = "C:\Temp\" & Right(strLine, (Len(strLine) - 8))

             Else

                OrdNum = Left(strLine,8)

                FileName = "C:\Temp\" & Right(strLine, (Len(strLine) - 9))

             End If            

            

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

session.findById("wnd[0]/tbar[0]/okcd").text = "/nmm43"

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

session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").text = OrdNum

session.findById("wnd[0]/usr/ctxtRMMW1-MATNR").caretPosition = 5

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

  Set Wshell = CreateObject("WScript.Shell")

        Wshell.run "C:\Temp\Upload.vbs " & FileName,1,False

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

     Loop

    objStream.Close

    objFile.Close

Else

         MsgBox "Could not find input file " & FILE_NAME & "."

End If

--------------------------------------------------------------

Input File

11214   Attach.txt

----------------------------------------------------------------

upload.vbs

Dim FileNam2

Set Wshell = CreateObject("WScript.Shell")

Do

bWindowFound = Wshell.AppActivate("Open")

WScript.Sleep 1000

Loop Until bWindowFound

bWindowFound = Wshell.AppActivate("Open")

if (bWindowFound) Then

Wshell.appActivate "Open"

WScript.Sleep 100

Wshell.sendkeys "{TAB}"

Wshell.sendkeys "{TAB}"

Wshell.sendkeys "{TAB}"

Wshell.sendkeys "{TAB}"

WScript.Sleep 100

FileNam2 = WScript.Arguments.Item(0) 

Wshell.sendkeys FileNam2

WScript.Sleep 100

Wshell.sendkeys "{ENTER}"

WScript.Sleep 100

end if