In our last post article, we discussed about Provide Minimize/Maximize Buttons in VBA Forms (Macro). In this lets take this a step ahead and see about adding icons to the VBA forms.
Using Icons Properties in Visual Basic forms we assign meaningful icons to the forms. But this property doesn’t exist while designing VBA forms.
In order to add the Icon to VBA form; kindly follow below code snippets.
Step 1: Add the Image from the toolbox on the Form and set its Name property to Img Icon.
Step 2: Variable declaration in the main module file.
Public Declare Function FindWindow Lib “user32” Alias “FindWindowA” _
(ByVal lpClassname As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function DrawMenuBar Lib “user32” _
(ByVal hwnd As Long) As Long
Public Const WM_SETICON = &H80
Public Const ICON_SMALL = 0&
Public Const ICON_BIG = 1&
Now let’s add the Icon to the form.
Step 3: Define method “AddIcon” in the user form.
Private Sub AddIcon()
‘Add an icon on the titlebar
Dim hwnd As Long
Dim lngRet As Long
Dim hIcon As Long
hIcon = Me.ImgIcon.Picture.Handle
hwnd = FindWindow(vbNullString, Me.Caption)
lngRet = SendMessage(hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
lngRet = SendMessage(hwnd, WM_SETICON, ICON_BIG, ByVal hIcon)
lngRet = DrawMenuBar(hwnd)
Step 4: On form activation; call the method to add the Icon to the user form:
Private Sub UserForm_Activate()
After execution you can notice the Icon has been added to the form.
Using above mentioned instructions Icons can be added to VBA forms (macro).
Greytrix a globally recognized Premier Sage Gold Development Partner is a one stop solution provider for Sage ERP and Sage CRM needs. Being recognized and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third party add-on development and implementation expertise.
Greytrix offers unique GUMU™ integrated solutions of Sage 300 with Sage CRM, Salesforce.com 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 and integration service for applications such as POS | WMS | Payroll | Shipping System | Business Intelligence | eCommerce for Sage 300 ERP and in Sage 300c development services we offer services such as upgrades of older codes and screens to new web screens, newer integrations using sdata and web services to Sage business partners, end users and Sage PSG worldwide. Greytrix offers over 20+ Sage 300 productivity enhancing utilities that we can help you with such as GreyMatrix, Document Attachment, Document Numbering, Auto-Bank Reconciliation, Purchase Approval System, Three way PO matching, Bill of Lading and VAT for Middle East.
For more details on Sage 300 and 300c Services, please contact us at firstname.lastname@example.org. We will be glad to assist you.