Microsoft Excel

Excel und VBA: Formeln, Programmierung, Lösungen

Die Excel/VBA-Beispiele

Thema

Schriftart der Statusbar verändern

Gruppe

Schrift

Problem

Wie kann ich die Schriftart in der StatusBar verändern?

Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.

StandardModule: basMain

Option Base 1
 Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" _
  (ByVal szClass$, ByVal szTitle$) As Long
 Declare Function GetWindow32 Lib "user32" Alias "GetWindow" _
  (ByVal hwnd As Long, ByVal wCmd As Long) As Long
 Declare Function GetClassName32 Lib "user32" Alias "GetClassNameA" _
  (ByVal hwnd As Long, ByVal lpClassName As String, _
  ByVal nmaxCount As Long) As Long
 Declare Function GetDC32 Lib "user32" Alias "GetDC" _
  (ByVal hwnd As Long) As Long
 Declare Function CreateFont32 Lib "gdi32" Alias "CreateFontA" _
  (ByVal H As Long, ByVal w As Long, ByVal E As Long, _
  ByVal O As Long, ByVal w As Long, ByVal i As Long, _
  ByVal u As Long, ByVal s As Long, ByVal c As Long, _
  ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, _
  ByVal PAF As Long, ByVal f As String) As Long
 Declare Function SelectObject32 Lib "gdi32" Alias "SelectObject" _
  (ByVal hdc As Long, ByVal hObject As Long) As Long
 Declare Function SetTextColor32 Lib "gdi32" Alias "SetTextColor" _
 (ByVal hdc As Long, ByVal crColor As Long) As Long
 Declare Function DeleteObject32 Lib "gdi32" Alias "DeleteObject" _
  (ByVal hObject As Long) As Long
 Declare Function ReleaseDC32 Lib "user32" Alias "ReleaseDC" _
  (ByVal hwnd As Long, ByVal hdc As Long) As Long

Sub MsgInBold()
 Dim hWndNext
 Dim hWndWks32 As Long
 Dim hDcWks32 As Long
 Dim hFont32 As Long, hFontOld32 As Long
 Dim sBuff As String * 255
 Dim a As Long

 Const GW_CHILD As Integer = 5
 Const GW_HWNDFIRST As Integer = 0
 Const GW_HWNDNEXT As Integer = 2

 Application.DisplayStatusBar = True

 'Get the handle of the Excel window
 hWndWks32 = FindWindow32("XLMAIN", Application.Caption)

 'Get a child window
 hWndNext = GetWindow32(hWndWks32, GW_CHILD)

 'Get the first child window
 hWndNext = GetWindow32(hWndNext, GW_HWNDFIRST)

 a = GetClassName32(hWndNext, sBuff, 255)
 hDcWks32 = GetDC32(hWndNext)

 'Create the font to use for the text
 'CreateFont(Height, Width, Escapement, Orientation, Weight, _
 '           Italic, Underline, Strikeout, CharSet, Precision, _
 '           Clipping, Quality, Pitch & Family, Font Name)
 '
 'Times New Roman, 32pt, Bold:
 '  CreateFont32(-32, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 0, _
   "Times NewRoman ")"
 '
 'MS Sans Serif, 12pt, Normal, Italic, Underline & Strikeout:
 '  CreateFont32(-12, 0, 0, 0, 400, 1, 1, 1, 0, 0, 0, 0, 0, _
   "MS SansSerif ")"

 hFont32 = CreateFont32(-32, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 0, _
   "Times New Roman")

 hFontOld32 = SelectObject32(hDcWks32, hFont32)

 'Display the message in the correct font
 Application.StatusBar = "Please press the OK button"

 'Display a message box
 MsgBox "How's that!"

 Application.StatusBar = False

 'Restore the original font
 a = SelectObject32(hDcWks32, hFontOld32)

 'Release the device context to the status bar
 a = ReleaseDC32(hWndNext, hDcWks32)

End Sub