cancel
Showing results for 
Search instead for 
Did you mean: 

Using Macro in Excel How to open a SAP directly?

Former Member
0 Kudos

Hi,

Can Anyone Suggest and help me to do above Code in Excel,"Using Macro in Excel How to open SAP directly"

Example: I want to Open T.CODE: MM01 directly, without login in to SAP, Using Macro, i want to open SAP Directly, Anyone Suggest me how to do it?.............

I Tried this But it showing Run time Error'438', Object does not support this property or method........

VBCODE:

Dim sap As Object

Dim conn As Object

Sub T_login()

Set sap = CreateObject("SAP.Functions")

Set conn = sap.Connection

conn.System = "production"

conn.client = "800"

conn.user = "SAPUSER"

conn.Password = "123456"

conn.Language = ""

conn.Tcode = "MM01"

If conn.logon(0, False) Then

MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"

Else

End If

If Not IsObject(SapGuiApp) Then

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

End If

If Not IsObject(Connection) Then

Set Connection = SapGuiApp.OpenConnection("production", True)

End If

If Not IsObject(session) Then

Set session = Connection.Children(0)

End If

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

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

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

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

session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus

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

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

Set wshell = CreateObject("Wscript.Shell")

wshell.Run Chr(34) & Path & "\script.vbs" & Chr(34), 1, 1

End Sub

Anyone send me the Exact code related to this.................

Its very immediate requirement.................

Regards

Karthick

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Imran,

Kindly open a new thread and place your question there.

You can do this from create --> Discussion.

I'll reply there.

Regards,

Ram

script_man
Active Contributor
0 Kudos

Hi Karthick,

You could try the following:


Sub Test()
If Not IsObject(SAPguiApp) Then
    Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
    Set Connection = SAPguiApp.OpenConnection("SYSTEMNAME", True)
End If
If Not IsObject(session) Then
    Set session = Connection.Children(0)
End If
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "123"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "USER"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "PASSWORD"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/tbar[0]/okcd").Text = "/nmm01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").maximize
. . .
MsgBox "If you click on the OK button, the SAP session is terminated."
End Sub

SAP GUI should appear in the new design, you must do the following:

START -> All Programs -> SAP Front End -> SAP GUI Configuration -> Application -> Add -> excel.exe -> Open

If the program is started from a VBS file, it must be entered here wscript.exe.

Regards,

ScriptMan

Former Member
0 Kudos

Thanks Script man, i'll Try it and get back to u.......... Thanks..........

Regards

Karthick

Former Member
0 Kudos

Hi ScriptMan,

I copied and pasted ur Coding, Now working with some Error,i Specfied below and I Don't have access to do Config and all

START -> All Programs -> SAP Front End -> SAP GUI Configuration -> Application -> Add -> excel.exe -> Open. If the program is started from a VBS file, it must be entered here wscript.exe.

Tht Option is disabled in my system, is there any other option is to do...

And when iam Runing ur code it displaying popup messages one by one.. Like this..

1. A Script is Opening a connection to SAPSytem

2.After then It Showing Error Message " Out of Memory", Thats it.. after No Output... how to rectify it...

3. Some times its opening SAP Login screen, Then we have to enter Manually...........

Is there Any method rectify it..........

Anyother option is there ScriptMan.. If possible send me code...........

Waiting For ur rply

Thanks & Regards

Karthick

script_man
Active Contributor
0 Kudos

Hi Karthick,

First of all I would do the following:

SAP GUI -> ALT / F12 (lokal layout tune) -> Options -> Scripting ->

Notify when a script connects to SAP GUI -> deactivate

Notify when a script establishes a connection -> deactivate

Then one would have to see what errors come else.

Regards,

ScriptMan

Former Member
0 Kudos

Hi Script man

Could you please provide me a macro code that will not close SAP application after completion of the task.

Thanks

Ram.

script_man
Active Contributor
0 Kudos

Hi Ram.,

this method I'd like to know too.

Regards,

ScriptMan

Former Member
0 Kudos

Very Thanks for Reply Scriptman.

I need another help from you.

Now, I'm using a code that you provided in a discussion.

The code opens a new SAP application and if we have an excisting session while running the macro it closes the excisting session and opens a new one. can you please help me to open a new session with the code without closing the excisting one.

Thanks

Ram

script_man
Active Contributor
0 Kudos

Hi Ram,

open a new thread and ask your question there again. Do not forget also to present the code you use.

Regards,

ScriptMan

Former Member
0 Kudos

Hey Script Man,

I have used your code by it showing run time error "1000" - "A script is opening a system SYSTEMNAME

Could you please help me

thomas_brutigam2
Active Participant
0 Kudos

Hi Meena,

did you allready open a System by the normal Logon ?

Former Member
0 Kudos

Hello Thomas or Anyone who can help,

I have had the similar issue as Praveen Meena,

while using my script to launch SAP through VBA macro in excel 2010.

After adding the excel.exe to sap gui applications it  failed to log me in through vba.

As far as I know I should be able to connect to SAP with no logging credentials (with no manual keying), VBA script already includes those credentials

This would be the first step.

Secondly I woul dlike to connect to specific T-Code and set the parameters to create a data for analysis...

I would appreciate professional assistance

Jack

Former Member
0 Kudos

Hi Script Man,

I copied your code as i have the same requirement to open a connection to SAP from Excel but i am receiving runtime error no. 429 ActiveX component cant create object. If you know how to correct this issue i would greatly appreciate. Thanks!!!

script_man
Active Contributor
0 Kudos

Hi Mary Joan,

please open a new thread and ask your question there again. Do not forget also to present the code you use and select the error line.


Regards,

ScriptMan

Former Member
0 Kudos

Hi Scriptman,

Herein the program, I have to enter my username and password, instead I would maintain the data in the same excel sheet, system has to pick the data from that tab. How is that possible?

Regards

Pradeepan.M

thomas_brutigam2
Active Participant
0 Kudos

Hi Pradeepan

please open a new thread and ask your question there again. Do not forget also to present the code you use.


Regards


Thomas B.