In our previous blogs on Accpac Macro, we discussed about features like providing icons to macro, Minimize/Maximize buttons, executing macro without logging in sage 300.
In this article, we will discuss about how we can enable macro to be displayed in the taskbar.
The New Stuff : Default settings for Receipts in Account Receivable in Sage 300 ERP
When we run macro from Sage300 desktop, it does not have a handle in windows task bar as other applications appear, due to this; often the user launches the same macro many times.
By adding the below code snippet, you can show the macro in windows taskbar.
Step 1: Variable declaration in the main module file.
<SNIP>
Public Declare Function FindWindow Lib “user32″ Alias “FindWindowA” _
(ByVal lpClassname As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowLong Lib “user32″ _
Alias “GetWindowLongA” _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowPos Lib “user32″ _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Public Declare Function SetWindowLong Lib “user32″ _
Alias “SetWindowLongA” _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const GWL_EXSTYLE = (-20)
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_SHOWWINDOW = &H40
Public Const WS_EX_APPWINDOW = &H40000
Public Const HWND_TOP = 0
</SNIP>
Step 2: Define method “AppTasklist” in the user form.
<SNIP>
Private Sub AppTasklist(myForm)
‘Add this userform into the Task bar
Dim WStyleAs Long
Dim Result As Long
Dim hwnd As Long
hwnd = FindWindow(vbNullString, myForm.Caption)
WStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
WStyle = WStyleOr WS_EX_APPWINDOW
Result = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or _
SWP_NOSIZE Or _
SWP_NOACTIVATE Or _
SWP_HIDEWINDOW)
Result = SetWindowLong(hwnd, GWL_EXSTYLE, WStyle)
Result = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or _
SWP_NOSIZE Or _
SWP_NOACTIVATE Or _
SWP_SHOWWINDOW)
End Sub
</SNIP>
Step 3: On form activation; call the method to add the macro to task bar:
<SNIP>
Private Sub UserForm_Activate()
AppTasklist Me
End Sub
</SNIP>
After execution you can notice the macro has been added to the taskbar.
Using above instructions VBA forms (macro) can be added at task bar.
Also Read :
1. VBA Macro Errors related to EXD Files
2. Macros in Sage 300 ERP
3. How To Add A Macro To Accpac Desktop of Sage 300 ERP
4. Run VBA Macro without Logging to Sage 300 ERP
5. Define Budget Using Macro