Run VBA Macro without Logging to Sage 300 ERP

By | May 15, 2013

In our previous blog, we discussed “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, the 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-mentioned 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 the 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 on the same machine, then the 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 (“”) strCommand, 6, True
set wshshell = nothing
‘Signon.SignoffSession SignonID
‘Set Signon = Nothing
strFoundProcess = True
Exit for
End If
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 (“”) 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.
About Us
Greytrix is a one-stop solution provider for Sage ERP and Sage CRM needs. We provide complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development and implementation expertise.
Greytrix has some unique solutions of Sage 300 integration with Sage CRM, and Magento eCommerce along with Sage 300 Migration from Sage 50 US, Sage 50 CA, Sage PRO, QuickBooks, Sage Business Vision and Sage Business Works. We also offer best-in-class Sage 300 customization and development services to Sage business partners, end users, and Sage PSG worldwide.
For more details on Sage 300 Services, please contact us at We will be glad to assist you.