Avatar of Al Rice
Al RiceFlag for United States of America

asked on 

Need help launching AS400 recorded macros Using VBA with PCOMM "StartMacro" Function

I am new to connecting to the AS400 using Windows Client Access emulator. I have written VBA scripts in Excel to load data to the AS400. Could someone suggest how to launch a AS400 macro using VBA. I have tried "STRPCO" and "STRPCCMMD", and "StartMacro" without success. I can select recorded macros from the CL menu, but I want to program the same in VBA. Any guidance would be appreciated.

I did make some progress with the "StartMacro" function, but halfway through running the macro, it aborted and I got the following Error:
         Runtime Error '440'
Emulator interface (ehllapi) error. reason 9

Any help would be much appreciated

Thanks
Al

Windows OSVBAVisual Basic Classic

Avatar of undefined
Last Comment
Al Rice
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

Pretty sure the internal macro language for IBM I Access for Windows is VBA.  Been a while but when recording a macro I recapp there are two options for format.  Select the VB option, and you should be able to include VBA code.
Avatar of Al Rice
Al Rice
Flag of United States of America image

ASKER

Actually the macro was developed by someone else and developed using python.  A portion (27 lines) of the 86 lines of python generated code is below:
Description =
[wait app]
[wait inp inh]
"20
[enter]
[wait inp inh]
wait 10 sec until FieldAttribute 0000 at (22,6)
wait 10 sec until cursor at (22,7)
[wait app]
[wait inp inh]
"7
[enter]
[wait inp inh]
wait 10 sec until FieldAttribute 0008 at (4,4)
wait 10 sec until cursor at (4,5)
[wait app]
[wait inp inh]
[tab field]
[tab field]
[tab field]
"1
[enter]
[wait inp inh]
wait 10 sec until FieldAttribute 0008 at (4,4)
[wait app]
[wait inp inh]
[pf3]
When calling the stored macro is works until a point and then it stops and throw the error mentioned earlier.  I read a previous post ["PCOMM Not Working In VBA All The Time" from spinningtop on 2009-11-23]  which referenced to same error, and you suggested an emulator patch upgrade which solved the problem with the user.  I did check with IT and below is the emulator version we currently running.  PerhapsIT did not include the specific service patch to address my problem.  
User generated imageHopefully this provides better, additional insite into my issue and you additional advice could progress towards a solution.

Thanks

Thats not Python.  That looks like a .MAC format recorded macro file.
Avatar of Al Rice
Al Rice
Flag of United States of America image

ASKER

Ahh... Should this be converted to .vbs to be compatible with the VBA code which is calling the macro?
Please advise... Thanks
Avatar of Al Rice
Al Rice
Flag of United States of America image

ASKER

Do you know an easy way to convert a group of AS400 Macros (*.mac) recorded in the PC5250 macro menu within iSeries Access for Windows emulator  to *.vbs using the PCOMM functions, such as "PCOMM.autECLConnList", "PCOMM.autECLSession", etc.)

Any help would be appreciated.

Thanks


Re-record macro.  No conversion mechanism I know of and I've done a lot of IBM I Access for Windows macro automation over the years.

Good news is .MAC format is easily human readable. 
Avatar of Al Rice
Al Rice
Flag of United States of America image

ASKER

I was hoping I did not need to re-record.  I asked this question in the context of the problem I am having trying to launch a recorded AS400 Macro from a VBA script using the IBM PCOMM functions.  When calling the recorded .mac macro, the macro launches, but runs very fast (seeming to ignore all the "wait" functions, and then it aborts (stops) and pops and error message (below) about 3/4 of the way through the macro.

         Runtime Error '440'
Emulator interface (ehllapi) error. reason 9

My thinking is the .mac macro behaves differently when launched from a VBA call versus being manually launched from the IBM I Access for Windows "play/record" menu.  Do you agree with my thinking?  If so, will re-recording the .mac macro as a .vbs script solve my problem.  

Thanks for the guidance.
Can't say I've ever tried to launch a .MAC macro file from a VBA script before, so I can't offer much guidance, there.  I have launched them from BAT scripts and probably Powershell.  I've also called ehllapi directly from VBScript.  

Unfortunately, error 9 isn't very helpful "A system error occurred".

Look at this thread for some general troubleshooting clues.  
https://www.experts-exchange.com/questions/24956712/AS400-PCOMM-Read-Write-Issue-in-VBA.html

Re-recording the macro as a .VBS may or may not help.  Suggest you create a simple test macro and try it.

How exactly are you attempting to launch the MAC macro from Excel VBA?  Can you show me the code?
ASKER CERTIFIED SOLUTION
Avatar of Al Rice
Al Rice
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo