You are here Function MsgBoxParams change icon, text color, back color, display progress in Excel VBA

Function MsgBoxParams change icon, text color, back color, display progress in Excel VBA

Function MSGBOXParams display icon from BSImageList, change text color, back color, display progress, unicode.

Do with step by step:

Step 1: Insert control BSImageList into Worksheet or Userform


Step 2: Add icon, image to control BSImageList
Right click on control BSImagelist, select "Properties". 

Click button "Add" to add any image file (ico, png, jpeg, bmp,....)


(BSImageList save images and keep ImageIndex using in controls: BSListView, BSTreeView, BSListBox, BSComboBox(x), BSButton, BSButtonEx,... to display icon).

Step 3: Coding MsgBoxParams 
 

 
Sub MsgBoxParams_Icon() 
   Dim pr As TBSMsgBoxParams 
   'pr.Icon = ExtractIcon(Application.HinstancePtr, GetSysDir & "\shell32.dll", 220)
   pr.Icon = Sheet2.BSImageList1.ListImages(1).HIcon 
   pr.BackColor = RGB(200, 10, 10) 
   pr.ForeColor = vbYellow 
   Dim x, s 
   s = "MsgBoxParams thay thÕ MsgBox ®Ó lµm ®­îc nhiÒu viÖc:" 
   s = s & Chr(13) & "- HiÓn thÞ chuçi Unicode" 
   s = s & Chr(13) & "- Thay ®æi mµu nÒn, ch÷" 
   s = s & Chr(13) & "- HiÓn thÞ thanh Progress ®Ó ch¹y thêi gian." 
   s = s & Chr(13) & "- Thay ®æi Icon" 
   x = MsgBoxParams(s, VbMsgBoxStyle.vbInformation + VbMsgBoxStyle.vbYesNoCancel, "Tïy biÕn víi MsgBox b»ng MsgBoxParams", pr) 
   DestroyIcon pr.Icon  'free memory!
End Sub 

Step 4: Run macro, you see MsgBox with color, icon

MsgBoxParams display progress

Sub MsgBoxParams_Progress() 
   Dim pr As TBSMsgBoxParams 
   'pr.Icon = ExtractIcon(Application.HinstancePtr, GetSysDir & "\shell32.dll", 220)
   pr.Icon = Sheet2.BSImageList1.ListImages(0).HIcon 
   pr.BackColor = RGB(200, 10, 10) 
   pr.ForeColor = vbYellow 
   pr.TimerStruct.bAddProgress = True 
   pr.TimerStruct.nDuration = 30  ' seconds
   pr.TimerStruct.nTimerCountDown = 0 
   pr.TimerStruct.bStopProgress = False 
   pr.TimerStruct.nInterval = 1000  ' 1 second
   pr.TimerStruct.nExpireButtonClick_ID = ID_YES 
   pr.TimerStruct.nDisplayOnButton_ID = ID_CANCEL 
   Dim x, s 
   s = "T«i sÏ h­íng dÉn c¸c b¹n tïy biÕn hµm MessageBox víi hµm MsgBoxParams cña BSAC trong %d gi©y n÷a." 
   s = s & Chr(13) & "- HiÓn thÞ chuçi Unicode" 
   s = s & Chr(13) & "- Thay ®æi mµu nÒn, ch÷" 
   s = s & Chr(13) & "- HiÓn thÞ thanh Progress ®Ó ch¹y thêi gian." 
   s = s & Chr(13) & "- Thay ®æi Icon" 
   x = MsgBoxParams(s, VbMsgBoxStyle.vbInformation + VbMsgBoxStyle.vbYesNoCancel, "Tïy biÕn víi MsgBox", pr) 
   MsgBoxW x, vbInformation, "MsgBoxParams" 
End Sub