- 06 Mar 2017 às 15:46
#20892
Este código corre bem em sistemas de 64 e 32, somente altera o icon pequeno no excel e o grande nao altera, somente no meu office 2010. Quando corro em outro office 2013 ou 2007 nao altera o Icon grande, será que alguém poderá ajudar
Abraços
Joao Santos
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function SendMessageA Lib "user32" (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
#Else
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private 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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0
Private Const ICON_BIG = 1
Sub setExcelIcon(Optional stFileName As String = "", Optional strIconIndex As Long = 0, Optional bSetBigIcon As Boolean = False, Optional bSetSmallIcon As Boolean = True)
Dim hIcon As Long
Dim hwndXLApp As Long
On Error Resume Next
hwndXLApp = FindWindow("XLMAIN", Application.Caption)
If hwndXLApp <> 0 Then
Err.Clear
If stFileName = "" Then
strIconIndex = 8000
hIcon = ExtractIcon(0, Application.Path & Application.PathSeparator & "Excel.exe", strIconIndex)
ElseIf Dir(stFileName) = "" Then
hIcon = 0
ElseIf Err.Number <> 0 Then
hIcon = 0
Else
hIcon = ExtractIcon(0, stFileName, strIconIndex)
End If
If bSetBigIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_BIG, hIcon
If bSetSmallIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_SMALL, hIcon
End If
End Sub
Sub Change_Icon_1()
setExcelIcon ThisWorkbook.Path &\Logo_Icon_RED.ico"
End Sub
Sub Reset_Icons()
setExcelIcon ""
End Sub
Abraços
Joao Santos
Option Explicit
#If Win64 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare PtrSafe Function SendMessageA Lib "user32" (ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
#Else
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private 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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0
Private Const ICON_BIG = 1
Sub setExcelIcon(Optional stFileName As String = "", Optional strIconIndex As Long = 0, Optional bSetBigIcon As Boolean = False, Optional bSetSmallIcon As Boolean = True)
Dim hIcon As Long
Dim hwndXLApp As Long
On Error Resume Next
hwndXLApp = FindWindow("XLMAIN", Application.Caption)
If hwndXLApp <> 0 Then
Err.Clear
If stFileName = "" Then
strIconIndex = 8000
hIcon = ExtractIcon(0, Application.Path & Application.PathSeparator & "Excel.exe", strIconIndex)
ElseIf Dir(stFileName) = "" Then
hIcon = 0
ElseIf Err.Number <> 0 Then
hIcon = 0
Else
hIcon = ExtractIcon(0, stFileName, strIconIndex)
End If
If bSetBigIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_BIG, hIcon
If bSetSmallIcon Then SendMessage hwndXLApp, WM_SETICON, ICON_SMALL, hIcon
End If
End Sub
Sub Change_Icon_1()
setExcelIcon ThisWorkbook.Path &\Logo_Icon_RED.ico"
End Sub
Sub Reset_Icons()
setExcelIcon ""
End Sub