Skip to Content
author's profile photo Former Member
Former Member

Calling Excel macro from Vbscript and come back to it

Hi Experts - I was wondering if anybody knows whether this can be done or not:

Start a VbScript in SAP, get a few files created and saved (this part is not problem), then the script opens up Excel and triggers an Excel macro which processes these files, and when done, it hands the control back to Vbscript that called it, and script continues to process from there. There were a few postings on how to open Excel and write data but I am not sure if I can call a macro this way.

Thanks

Umur

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 25, 2010 at 07:48 PM

    Hi Umur,

    yes you can !

    Just pass some Parameters to the Application

    like this for example:

    xclapp.Run "Mappe3.xls!Modul1.TestSub"
    

    If you wanna be shure to get "back" to your vbs then

    you better make a "break" after calling Excel and let it do all the work...

    after Excel is through call another vbs that is doing the last arguments...

    Edited by: Thomas Br on May 25, 2010 9:49 PM

    Add a comment
    10|10000 characters needed characters exceeded

    • can you help me

      i have different condition in which in excel there will be exact format for changing customer's excise details.

      excel macro will call from same excel file, update details in sap and will add message to next column in excel and control come back to excel.

      below is code. it is working but it exit the all excel window at last,

      instead it should not close the excel and give controls back to excel from where macro is been called.

      -


      code----


      Sub saps()

      If Not IsObject(SAPguiApp) Then

      Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")

      End If

      If Not IsObject(Connection) Then

      Set Connection = SAPguiApp.OpenConnection("dev", False)

      End If

      If Not IsObject(session) Then

      Set session = Connection.Children(0)

      End If

      'If IsObject(Excel) Then

      ' WScript.ConnectObject session, "on"

      ' WScript.ConnectObject Application, "on"

      'End If

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

      session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "009"

      session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "abap1"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "pctablet"

      session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").SetFocus

      session.findById("wnd[0]/usr/pwdRSYST-BCODE").caretPosition = 8

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

      If session.Children.Count > 1 Then

      session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").Select

      session.findById("wnd[1]/usr/radMULTI_LOGON_OPT2").SetFocus

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

      End If

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

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

      session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").Text = Excel.Cells(2, 2).Value

      session.findById("wnd[1]/usr/ctxtRF02D-BUKRS").Text = "1000"

      session.findById("wnd[1]/usr/ctxtRF02D-BUKRS").SetFocus

      session.findById("wnd[1]/usr/ctxtRF02D-BUKRS").caretPosition = 4

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

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

      session.findById("wnd[0]/usr/tabsCIN_CUSTOMER/tabpCIN_CUSTOMER_FC1/ssubCIN_CUSTOMER_SCA:SAPLJ1I_MASTER:0201/txtJ_1IMOCUST-J_1IEXCD").Text = Excel.Cells(2, 3).Value

      session.findById("wnd[0]/usr/tabsCIN_CUSTOMER/tabpCIN_CUSTOMER_FC1/ssubCIN_CUSTOMER_SCA:SAPLJ1I_MASTER:0201/txtJ_1IMOCUST-J_1IEXCD").caretPosition = 2

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

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

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

      MsgBox "exise details updated", vbOKOnly, "Comment"

      End Sub

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.