Windows notification adalah sebuah popup yang muncul pada kanan bawah windows. Tidak hanya bahasa pemrograman lain, VBA juga bisa mengakses dan menggunakan Windows notifaction ini.
Untuk menggunakan windows notifcation, bisa memanfaatkan sebuah fungsi dari Windows API yang bernama Shell_NotifiIcon.
Simpan Windows API berikut ini dalam module, Windows API ini sudah menggunakan compiler directive sehingga support digunakan di system 64bit dan juga 32bit.
#If VBA7 And Win64 Then Declare PtrSafe Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" ( _ ByVal dwMessage As Long, _ ByRef lpdata As NOTIFYICONDATA) As Long #Else Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" ( _ ByVal dwMessage As Long, _ ByRef lpData As NOTIFYICONDATA) As Long #End If Public lpdata As NOTIFYICONDATA Const NIM_ADD = &H0 Const NIM_MODIFY = &H1 Private Type NOTIFYICONDATA cbSize As Long hWnd As LongPtr uID As Long uFlags As Long uCallbackMessage As Long hIcon As LongPtr szTip As String * 128 dwState As Long dwStateMask As Long szInfo As String * 256 uTimeout As Long szInfoTitle As String * 64 dwInfoFlags As Long End Type
Selanjutnya untuk menggunakan API diatas, buat sebuah Function seperti dibawah ini:
Function kirimNotif(ByVal judul As String, pesan As String, flag As Long) With lpdata .szInfoTitle = judul .szInfo = pesan .dwInfoFlags = flag .cbSize = 504 .uFlags = &H10 End With Shell_NotifyIcon NIM_ADD, lpdata Shell_NotifyIcon NIM_MODIFY, lpdata End Function
Setelah semua script diatas sudah disimpan dalam Module, untuk menggunakan atau mengirim notif bisa gunakan pemanggilan fungsi sebagai berikut.
kirimNotif "Hi", "Saya andi Setiadi", 0
Dan berikut ini hasil ketika dijalankan.
Untuk lebih jelas tentang tutorial ini bisa ditonton melalui youtube diatas.