Skip to Content
avatar image
Former Member

FB03 Exporting of attachment

Hi guys!

I am currently developing a macro tool wherein I can export the attachment of a document using FB03 and saving it in a specific folder.

I was able to create one but I have the following problem:

> I don't know why there is an error with the path of the file whenever I try to link specific paths to a cell from my excel. But when I input the path directly to the VBA, it works. (hope this question was clear. 😔)

> I am a VBA beginner so I would like to loop this macro and I want it to perform the export for a list of documents and not just one.

> Is it possible for me to insert the exported file into the excel sheet next to the document number?

Hope I was clear with what intend to do...Please help. 😔

THANK YOU SO MUCH!!

Below are the details that I have in my Excel sheet

A B C 1 Destination File C:\Users\LIX2628\Desktop\PUll outs export\ 2 Document Number Co. Code Year 1200072996 u001 2014

And below is the script that I used.

Sub FB03export()

Dim application

If Not IsObject(application) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   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

session.findById("wnd[0]").resizeWorkingPane 196, 15, False

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

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

session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = Cells(3, 2).Value

session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = Cells(3, 3).Value

session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = Cells(3, 4).Value

session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus

session.findById("wnd[0]/usr/txtRF05L-GJAHR").caretPosition = 4

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").selectedRows = "0"

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").contextMenu

session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectContextMenuItem "%BDS_START_BDN"

session.findById("wnd[0]/shellcont[1]/shell").selectedNode = "Doc-00000001"

session.findById("wnd[0]/mbar/menu[0]/menu[6]").Select

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").Text = "C:\Users\LIX2628\Desktop\PUll outs export\"

session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]").caretPosition = 42

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[3]").press

session.findById("wnd[1]/tbar[0]/btn[12]").press

session.findById("wnd[0]/tbar[0]/btn[3]").press

End Sub

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Dec 11, 2015 at 08:10 PM

    Hi Vedette,

    I would like to ask you if you have been successful to complete your coding for this? I too have the same issue. Could you please help with the coding?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      David - Add the following at your commented section:

      Set WshShell = CreateObject("WScript.Shell")

      WshShell.sendkeys Attachment

      WshShell.sendkeys "%S" 'If saving

      WshShell.sendkeys "%Y" 'If an overwrite is needed

      Good luck,

      Joe

  • avatar image
    Former Member
    Jul 17, 2016 at 07:52 PM

    Hi People

    I have the same problem, i can't open the window explorer for atachment from fb03 with VBA, I have been reading ABAP resource but is not working yet.

    Someone can reply with code? Or is not possible, thanks

    Bst Regardings

    Lucas

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Good Day,

      Can  you please help me, i have been created this vba code below, but i can't finish with the code that you sent me. Thank for your attention.

      Sub Attach_DOC_FB03()

      If Not IsObject(application1) Then
         Set SapGuiAuto = GetObject("SAPGUI")
         Set application1 = SapGuiAuto.GetScriptingEngine
      End If
      If Not IsObject(Connection) Then
         Set Connection = application1.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 application1, "on"
      End If

      Dim a As Integer
      a = 2
      Do While Not Range("a" & a) = ""
      On Error Resume Next

      session.findById("wnd[0]").maximize
      session.findById("wnd[0]/tbar[0]/okcd").Text = "/nfb03"
      session.findById("wnd[0]").sendVKey 0
      session.findById("wnd[0]/usr/txtRF05A-BELNS").Text = Range("b" & a) & ""
      'session.findById("wnd[0]/usr/txtRF05A-GJAHS").Text = Range("b" & a) & ""
      'session.findById("wnd[0]/usr/txtBSIS-MONAT").Text = Range("d" & a) & ""
      session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = "br04"
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = "2016"
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus
      session.findById("wnd[0]/usr/txtRF05L-GJAHR").caretPosition = 4
      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_PCATTA_CREA"


      "Doens't works from here"

          bWindowFound = Wshell.AppActivate("Import file")

          WScript.Sleep 1000

      Loop Until bWindowFound

      bWindowFound = Wshell.AppActivate("Import file")

      If (bWindowFound) Then

          Wshell.AppActivate "Import file"

          Wshell.SendKeys "{TAB}"

          Wshell.SendKeys "{TAB}"

          Wshell.SendKeys "{TAB}"

          Wshell.SendKeys "{TAB}"

          Wshell.SendKeys "{TAB}"

          Wshell.SendKeys fileAdd

          Wshell.SendKeys "{ENTER}"

      End If

      'session.findById("wnd[0]").sendVKey 0
      'session.findById("wnd[0]/usr/txtRF05L-BELNR").Text = Range("a" & a) & ""
      'session.findById("wnd[0]/sbar").DoubleClick
      'Range("d" & a) = session.findById("wnd[0]/sbar").Text

      a = a + 1

      Loop

      End Sub