Quantcast
Channel: Sage 300 ERP – Tips, Tricks and Components
Viewing all articles
Browse latest Browse all 1475

Run VBA Macro without Logging to Sage 300 ERP

$
0
0

In our previous blog, we discussed about “VBA Macro Errors related to EXD File”. Now let’s see how to run VBA macro file without logging to Sage 300 ERP (formerly Sage Accpac ERP) or directly from scheduler in unattended mode.

Say, user wants to schedule a macro in unattended mode from windows scheduler, without continuously keeping Sage 300 session logged in, as it is essential for a macro to execute.

Users would be able to achieve it by using the below code snippet. Wherein, we have automated the process to create a Sage 300 session, and provided it to the macro to execute successfully.  

Follow below mention steps to execute;

1. Copy below code and paste in Notepad[++].
2. Change macro file name, user, password, and company in VBS file before running.
3. Then save file as RunMacro.VBS.
4. Execute VBS script or schedule the .VBS file in windows scheduler.

Note: If there are multiple Sage 300 session open in same machine, then macro will pop-up Sage 300 login screen.

Also Read: “HTTP Error 500.0 Internal Server Error” while Configuring IIS for Sage 300 Portal

<Code Snip>

Dim Signon
Dim SignonID
Dim strCommand
Dim AllProcess
Dim Process
Dim strFoundProcess
strFoundProcess = False
Set AllProcess = getobject(“winmgmts:”) ‘create object
For Each Process In AllProcess.InstancesOf(“Win32_process”) ‘Get all the processes running ‘in your PC
If (Instr (Ucase(Process.Name),”ACCPAC.EXE”) = 1) Then ‘Made all uppercase to ‘remove ambiguity. Replace TASKMGR.EXE with your application name in CAPS.
‘msgbox “Application is already running!” ‘You can replace this with ‘Reporter.ReportEvent
‘Change the macro name and path
strCommand = “A4WVBA.EXE -r -f “”E:\Program Files\Sage\Sage Accpac\OE60A\XXX.avb”"”

Set wshShell = WScript.CreateObject (“WSCript.shell”)
wshshell.run strCommand, 6, True
set wshshell = nothing

‘Signon.SignoffSession SignonID

‘Set Signon = Nothing
strFoundProcess = True
Exit for
End If
Next
If strFoundProcess = False Then
‘msgbox “Go ahead!Application is not running” ‘You can replace this with ‘Reporter.ReportEvent
Set Signon = CreateObject(“A4wSignonMgr.AccpacSignonMgr”)
‘Change the Signon paramters to match the company login
‘SignonID = Signon.RegisterSignon(“USERID”, “PASSWORD”, “COMPANYID”, “Company Name”, Date)
‘USERID = Accpac user in upper case
‘PASSWORD = Accpac user password in upper case
‘COMPANYID = Accpac company ID in upper case
SignonID = Signon.RegisterSignon(“ADMIN”, “ADMIN”, “SAMINC”, “Sample Company”, Date)

‘Change the macro name and path
strCommand = “A4WVBA.EXE -r -f “”E:\Program Files\Sage\Sage Accpac\OE60A\XXX.avb”"”

Set wshShell = WScript.CreateObject (“WSCript.shell”)
wshshell.run strCommand, 6, True
set wshshell = nothing

Signon.SignoffSession SignonID

Set Signon = Nothing
End If
Set AllProcess = nothing

</Code Snip>

User just needs to add RunMacro.VBS file in scheduler in order to run macro without logging to Sage 300 ERP.

Related Posts:

1. “Windows has blocked this software because it can’t verify the publisher” error in Sage 300 ERP
2. Statement Designer Error in Financial Report of Sage 300 ERP
3.  “You do not have a license to use this product” Error in Sage 300 ERP
4. Custom Report error in Sage 300 ERP


Viewing all articles
Browse latest Browse all 1475

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>