SAP Logon 760 via VBA - vba

since the SAP update my vba application fails to connect to the sap system.
My previous code does not work anymore. I guess it is because of the new subfolder. The subfolder "All Urt SAP Systems" and "01 Test System" did not exist in the past.
However this code worked in the past without the new subfolders:
Set rotentry = GetObject("SAPGUI")
Set App = rotentry.GetScriptingEngine
App.Application.DisplayAlerts = False
Set Connection = App.OpenConnection("TE1 (Test - Development System)") '<-- Here comes the error
Set Session = Connection.Children(0)
Does anybody know what I am missing here? I tried a few SAP forums without success.
I am getting the following error message:
SAP Logon connection entry not found

Related

wnd[1] not found with .findById()

I'm new to SAP scripting. Someone told me it is possible to automatize my work with VBA, so I looked into it. I looked on the internet how to connect, it works fine. I use the recorder to know what code to write. Everything works very well until the last line of this code:
session.findById("wnd[0]/usr/ctxtCAUFVD-AUFNR").Text = "000000000" 'write service order number
session.findById("wnd[0]").sendVKey 0 'Confirm (enter)
session.findById("wnd[0]/mbar/menu[0]/menu[9]/menu[2]/menu[4]").Select 'execute a function to close the order
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press 'A popup appears (always) with "No" in autoselect. I want to click on "Yes"
.findById("wnd[1]") should allow me to use the confirmation popup window, but it always returns Error 619, Control not found. I have no idea why, since this line was written by the recorder. I explored for many hours the Internet and I can't find the answer.
Thank you in advance for your help.
Of course, I needed to ask to have the resolution idea...
The was I set up my connection was that session was actually the SAP session .ActiveWindow(), therefore only wnd[0]. It couldn't find wnd[1]. I execute the findById() from the SAP session and it works.
If Not IsObject(SAPGuiApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPGuiApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPGuiApp.Children(0)
End If
If Not IsObject(SAP_session) Then
Set SAP_session = Connection.Children(0)
End If
Set session = SAP_session.ActiveWindow()
session.findById("wnd[1]") 'Bad. session is only wnd[0]
SAP_session.findById("wnd[1]") 'Good it can find wnd[0] and wnd[1]

Does anyone know how to automate SAP Login in Automation Anywhere 11

enter image description hereI am using Vb script to launch SAP logon application and successfully able to launch and login into SAP, but the issue, the next line of code is not getting executes until the application is closed.
Any approach how to achieve please suggest.
VB Script Code
[set WshShell = CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set proc = WshShell.Exec("C:\Program Files (x86)\SAP GUI_7.40_P10_LITE (VMware ThinApp)\saplogon.exe")
Do While proc.Status = 0
WScript.Sleep 100
Loop
Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
Set Connection = Appl.Openconnection("connectioname", True)
Set session = Connection.Children(0)
session.findById("wnd\[0\]/usr/txtRSYST-BNAME").Text = "username"
session.findById("wnd\[0\]/usr/pwdRSYST-BCODE").Text = "password"
session.findById("wnd\[0\]/usr/txtRSYST-LANGU").Text = "EN"
session.findById("wnd\[0\]").sendVKey 0][1]
Please refer https://botstore.automationanywhere.com/bot/sap-utilities/ , it is free. Just install it and you will be able to use the metabot.
I'd suggest not to use VBScript so extensively for SAP Automation. Metabots are highly compatible and reliable when it comes to SAP Automation. I can provide you SAP DLL (if you need), you can just import it and start using it. In this case, steps to Login to SAP would be as below.
Launch SAP (Program/File Command)
Wait for Window
The rest could be easily done with Metabot DLLs
Also, "the next line of code is not getting executes until the application is closed.", which line of code are you referring to exactly? Is it session.findById("wnd[0]").sendVKey 0][1]
Please try session.findById("wnd[0]").sendVKey [1] or session.findById("wnd[0]").sendVKey [0][1]
you will need the SAP DLL metbot if you are using v11 of AA
doc: https://docs.automationanywhere.com/bundle/enterprise-v11.3/page/enterprise/topics/aae-client/bot-creator/commands/using-bapi-to-automate-task.html

application run method "error application-defined or object-defined error"

I'm trying to run a sub for access using the Access.application.run method. It keeps on bringing up error:
40351 "error application-defined or object-defined error"
The code is very basic:
Dim objAccess, wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Set objAccess = CreateObject("Access.Application")
With objAccess
.OpenCurrentDatabase ("c:\coxi\Documents\Personnal\investment\5334_2.accdb")
.Run "test"
Set .CurrentProject = Nothing
End With
the routine errors on the .run line
Root cause: Your code is trying to open un-trusted access DB "5334_2.accdb"
Fix:
Open access application
Goto Trusted center settings under options.
Add the location of the Access DB file.
Retry executing the code.
Thanks a lot !
I had the same hidden problem and could resolve it this way!
I edited code in an .accdb database on the C: drive (C:\…\…\…) and signed the Word templates. Everything worked well, including some Word integration in both directions (Word calling Access procedures and conversely).
When I copied the Access database and the Word templates onto my standard database path (D:\…\…), both the Access database and the Word templates performed well, with the exception of error 40351 in Word on the AccessObj.run "Myproc" …
A pity that neither Word nor Access display a dialog to enable the Access code or at least a sound error message.

VBA Excel won't connect to Access DB on another computer

A colleague of mine is trying to use an excel tool that pulls data from an access database. The tool works perfectly on my computer but he is having the issue that the tool is unable to connect with the Access database.
I've tried solving the problem by checking that the excel options are correct i.e. making sure macros are enabled etc. but I'm still getting the problem.
The problem must be something in my colleagues settings that hasn't been configured because the tool works without any issues for me. Here are some of the parts of the code that read the Access DB:
Public Const pActuarialPWD = "password2"
Public Const QuoteDB = "N:\DWH\Commercial Ins\Fleet\Databases\Quote DB.accdb"
If bDBOpen = False Then
'Connect to database
If openQuotedb() = False Then
MsgBox "Connection to database failed - contact Actuarial"
Exit Sub
End If
End If
Function openQuotedb()
On Error GoTo ErrorHandler
openQuotedb = False
Set db = OpenDatabase(QuoteDB, False, False, "MS Access;PWD=" & pActuarialPWD)
openQuotedb = True
Exit Function
ErrorHandler:
MsgBox "Couldn't connect to database. Please contact actuarial. Tool should not be used, as quote information will be lost", vbCritical
End Function
I've stepped through the program both in my computer and my colleagues a number of times and I can't see what the problem is. When I step past the line of code "db = ..." on my colleagues PC and hover over db it reads "db = Nothing" whereas on mine it successfully connects to the database.
Have you any ideas what might be going wrong here. It just seems exces is not setup properly to connect to Access on my colleagues PC.
The only thing I can think of is that I am using Excel 2013 and my colleague is on 2010.
The function below have saved me a lot of trouble. I don't know if it will solve your problem but in general will help.
I have tested it in many applications and with a variety of changes and variables and it worked every time and has never failed me. Maybe will help you.
Public Function db_connect(Optional sel_db As Variant = "", Optional pass_be As Variant = ";PWD=<password>") As DAO.Database
Dim db As DAO.Database
If sel_db = "" Then
sel_db = "<database_path>"
End If
On Error GoTo db_locked:
Set db = DBEngine.OpenDatabase(sel_db, True, False, pass_be)
GoTo DBclose:
db_locked:
Sleep 100
Set db = DB_Connection.db_connect(sel_db, pass_be)
DBclose:
Set db_connect = db
End Function
To call the function just do:
Dim db As DAO.Database
Set pers = DB_Connection.db_connect("full_path or your path with the N drive mapped", ";PWD=<db_password>")
WARNING-DISCLAIMER!!!
Be careful. The function has a waiting mechanism and tries to connect without never stoping. If you have wrong parameters or the database doesn't exist then it will stuck in an infinite loop. I never bothered to fix it because I knew the problem and avoid it. However, you can make improvements if you want.

Multiple instances of same access database are open on 1 machine - problem

I'm having issues with a ms access 2007 accdb, using Windows Server 2008 task scheduler for scheduled tasks. The problem is the file that's being opened by the task scheduler is opening/closing properly, but the 'lock' file (.laccdb) remains visible after the database is closed, which is an indicator that the access db thinks it's still open. Each time a new task runs, a new instance of access is being opened. I opened the Schema to show roster of all users in the database and it's showing 3 duplicates of the server name/Admin account. Below is an example of the immediate window in access:
COMPUTER_NAME LOGIN_NAME CONNECTED SUSPECT_STATE
SERVER Admin True Null
SERVER Admin True Null
SERVER Admin True Null
I'm hoping someone else has had this problem and knows 1) How to easily close all the open instances of access and 2) how to prevent this from occuring when running a task. I have "Do not start a new instance" set under the task's 'settings' tab, but this is irrelevant b/c none of the tasks were running simultaneously. Thanks in advance for any assistance.
To close all open Access instances (you can't run this from Access because you can't guarantee that the running instance will be the last reference you retrieve):
Sub CloseAllAccessInstances()
Dim acc As Access.Application
Do
Set acc = GetObject(, "Access.Application")
If IsNull(acc) Then Exit Do
acc.Quit
Loop
End Sub
After you run the above, check the task manager. If you see msaccess.exe, then you most likely have a circular object reference. This will prevent Access from closing. For more information, have a look at http://msdn.microsoft.com/en-us/library/aa716190(VS.60).aspx.