Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
628to632
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
628to632
628to632
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Excel Fenster - Titelleiste bearbeiten

Excel Fenster - Titelleiste bearbeiten
24.06.2005 00:34:35
Chris
Guten Abend nochmal.
Kann man im Excel-Fenster per VBA die Titelleiste bearbeiten?
Ich würde mein Projekt gerne mit eigenem Namen sehen und vor allem
das Excel-Logo ganz links außen gegen ein anderes austauschen.
Außerdem hätte ich gern das beim Start meines Projektes nur die Titelleiste
zu sehen ist und die Datei-Leiste und die Symbolleisten sollen ausgeblendet werden.
Ist sowas machbar?
Nächtliche Grüße
Chris B.

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Excel Fenster - Titelleiste bearbeiten
24.06.2005 00:53:36
Matthias
Hallo Chris,
in "DieseArbeitsmappe":

Private Sub Workbook_Activate()
Dim cb As CommandBar
Application.Caption = "Mein Projekt"
ActiveWindow.Caption = "Version 1"
For Each cb In Application.CommandBars
cb.Enabled = False
Next
Application.DisplayFormulaBar = False
SetXLAppIcon
End Sub
Private Sub Workbook_Deactivate()
Application.Caption = ""
Dim cb As CommandBar
For Each cb In Application.CommandBars
cb.Enabled = True
Next
Application.DisplayFormulaBar = True
ResetXLAppIcon
End Sub

und in ein normales Modul:

Option Explicit
'Code von Stratos Malasiotis
'Win32 API Function Declarations
Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) _
As Long
Declare Function FindWindowEx _
Lib "user32" _
Alias "FindWindowExA" _
( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String _
) _
As Long
Declare Function ExtractIcon _
Lib "shell32.dll" _
Alias "ExtractIconA" _
( _
ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long _
) _
As Long
Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" _
( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lparam As Long _
) _
As Long
'Win32 API Constant Declarations
Const WM_SETICON As Long = &H80
'Custom function for changing Excel's windows icons
Public Function fncSetXLWindowIcon _
( _
Optional IconFile As String = vbNullString, _
Optional WorkbookName As String = vbNullString _
) _
As Boolean
'Variable Declarations
Dim XLMAINhWnd  As Long, XLDESKhWnd       As Long, _
EXCEL7hWnd  As Long, TargetWindowhWnd As Long, _
VirtualIcon As Long
'initialise the result of the function to false; assume failure
fncSetXLWindowIcon = True
'STEP 1. Identify the target window
'get the caption from the first window of the specified workbook; if any
On Error Resume Next
If CBool(Len((Workbooks(WorkbookName).Name))) Then
WorkbookName = Workbooks(WorkbookName).Windows(1).Caption
End If
On Error GoTo ExitFunction
'if a caption has been extracted get a hendle to that workbook window;
'else get a handle to Excel's main window
If Not WorkbookName = vbNullString Then
XLMAINhWnd = FindWindow("XLMAIN", Application.Caption)
XLDESKhWnd = FindWindowEx(XLMAINhWnd, 0, "XLDESK", vbNullString)
TargetWindowhWnd = FindWindowEx(XLDESKhWnd, 0, "EXCEL7", WorkbookName)
Else
XLMAINhWnd = FindWindow("XLMAIN", Application.Caption)
TargetWindowhWnd = XLMAINhWnd
End If
'if  we couldn't get a handle, exit the function
If TargetWindowhWnd = 0 Then Exit Function
'STEP 2. Extract the icon from the respective file
If IconFile = vbNullString Then
'assume that the user asked to restore the original icon
VirtualIcon = 0
Else
'try to extract the icon from the specified file
VirtualIcon = ExtractIcon(0, IconFile, 0)
'If the file could not be found (1), or if the no icon could be
'found in the file (0), exit the function
If VirtualIcon <= 1 Then Exit Function
End If
'STEP 3. Send a Windows message to the specified window to change
'        its icon
'in most cases only the second (False) message is adequate
SendMessage TargetWindowhWnd, WM_SETICON, True, VirtualIcon
SendMessage TargetWindowhWnd, WM_SETICON, False, VirtualIcon
'the functio has been completed succesfully
fncSetXLWindowIcon = True
ExitFunction:
End Function
Sub SetXLAppIcon()
'set XL's main window icon
fncSetXLWindowIcon "e:\icons\dp1.ICO"
End Sub
Sub ResetXLAppIcon()
'restore XL's main window icon
fncSetXLWindowIcon
End Sub
Sub SetXLWindowIcon()
'set active workbook's window icon
fncSetXLWindowIcon "e:\icons\32-smile.ICO", ActiveWorkbook.Name
End Sub
Sub ResetXLWindowIcon()
'restore active workbook's window icon
fncSetXLWindowIcon , ActiveWorkbook.Name
End Sub

Der Pfad zu den .ICO-Dateien muss noch angepasst werden.
Gruß Matthias
Anzeige
AW: Excel Fenster - Titelleiste bearbeiten
24.06.2005 07:59:29
CLaus
Wenn DU die Titelleiste aenderst, dann funktioniert u.U. Windows("NameAlt").activate nicht mehr... das ist bei mir jedenfalls so gewesen...
Anders ist das bei der Statusbar (unten...):
Sinnvollerweise speicherst Du Dir die Originale Statusbar in eine Variable, bevor Du sie "umbenennst", dann kannst Du sie nachher wieder zurückbenamsen...
oldStatusBar = Application.DisplayStatusBar
Application.StatusBar = "Abfrage läuft..."
...
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
Gruss
Claus
AW: Excel Fenster - Titelleiste bearbeiten
24.06.2005 08:05:58
Matthias
Hallo Claus,
Um dem System die Steuerung der Statusbar wieder zu übergeben, genügt ein Application.Statusbar = False. Was soll da zwischengespeichert werden?
Gruß Matthias
Anzeige
AW: Excel Fenster - Titelleiste bearbeiten
24.06.2005 08:30:17
Erich
Hallo Claus,
es gibt nut eine Statusbar, die man anzeigen lassen kann oder nicht. Sie kann aber nicht "umbenannt" oder zwischengespeichert werden.
Mit Application.DisplayStatusBar (=True oder False) wird nur gesteuert, ob die Statusbar sichtbar sein soll oder nicht. Diesen Zustand kann man speichern und wiederherstellen.
Mit Application.StatusBar = "Irgendwas" oder False kann man selbst einen Text in die Statusbar stellen oder Excel die Kontrolle überlassen.
Grüße aus Kamp-Lintfort
Erich
AW: Excel Fenster - Titelleiste bearbeiten
24.06.2005 17:37:59
Chris
Hallo zusammen.
Also bei läuft der Code von Matthias völlig problemlos.
Dankeschön dafür. Das war genau was ich gesucht habe. ;o)
Könnt ihr mir vielleicht noch sagen ob ich das Icon auch im Arbeitsblatt hinterlegen kann?
Ich möchte dieses Projekt an verschiedene Leute weitergeben, und da wärs unpraktisch wenn
jeder erst ein Icon in einen bestimmten Pfad packen muß damits richtig funktioniert...
Gruß Chris
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige