Private Function MsgBoxEx( _
ByVal Prompt As String, _
Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional ByVal Title As String, _
Optional ByVal HelpFile As String, _
Optional ByVal Context As Long, _
Optional ByVal FontName As String, _
Optional ByVal FontSize As Single, _
Optional ByVal FontBold As Boolean, _
Optional ByVal FontItalic As Boolean, _
Optional ByVal FontUnderline As Boolean, _
Optional ByVal FontStrikeOut As Boolean _
) As VbMsgBoxResult
Dim tDefNCMetrics As NONCLIENTMETRICS, tNCMetrics As NONCLIENTMETRICS, tLogFont As LOGFONT
On Error GoTo ErrHandler
tNCMetrics.cbSize = Len(tNCMetrics)
Call SystemParametersInfo(SPI_GETNONCLIENTMETRICS, Len(tNCMetrics), tNCMetrics, 0)
tDefNCMetrics = tNCMetrics
[B][COLOR=#ff0000] Debug.Print "FontName: "; tNCMetrics.lfMessageFont.lfFaceName[/COLOR][/B]
[COLOR=#ff0000][B] Debug.Print "FontSize: "; tNCMetrics.lfMessageFont.lfHeight[/B][/COLOR]
[B][COLOR=#008000] 'Safety step : Save to text file In case an error occurs and the default NONCLIENTMETRICS are lost.[/COLOR][/B]
[B][COLOR=#008000] 'To recover the default NONCLIENTMETRICS, run the 'RestoreDefaultNCMetrics' routine located below.[/COLOR][/B]
Open ThisWorkbook.Path & Application.PathSeparator & "DefNCMetrics.txt" For Binary As [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL]
Put [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL] , , tDefNCMetrics
Close [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1"]#1[/URL]
With tLogFont
.lfFaceName = IIf(Len(FontName), FontName & Chr$(0), tDefNCMetrics.lfMessageFont.lfFaceName & Chr$(0))
.lfHeight = IIf(FontSize, -FontSize, tDefNCMetrics.lfMessageFont.lfHeight)
.lfWeight = IIf(FontBold, 900, tDefNCMetrics.lfMessageFont.lfWeight)
.lfItalic = IIf(FontItalic, True, tDefNCMetrics.lfMessageFont.lfItalic)
.lfUnderline = IIf(FontUnderline, True, tDefNCMetrics.lfMessageFont.lfUnderline)
.lfStrikeOut = IIf(FontStrikeOut, True, tDefNCMetrics.lfMessageFont.lfStrikeOut)
End With
hFont = CreateFontIndirect(tLogFont)
tNCMetrics.lfMessageFont = tLogFont
Call SystemParametersInfo(SPI_SETNONCLIENTMETRICS, Len(tNCMetrics), tNCMetrics, SPIF_UPDATEINIFILE)
MsgBox Prompt, Buttons, IIf(Len(Title), Title, Application.Name), HelpFile, Context
ErrHandler:
DeleteObject hFont
Call SystemParametersInfo(SPI_SETNONCLIENTMETRICS, Len(tDefNCMetrics), tDefNCMetrics, SPIF_UPDATEINIFILE)
If Err.Number = 75 Then
MsgBox "Oops!" & vbCr & vbCr & "This workbook must be saved to disk" & vbCr & "before running the code.", vbInformation
End If
End Function