• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

HOW TO CHANG E THE ICON OF A PARTICULAR EXCEL FILE ?

mahaveer

Member
Actually i m using EXCEL 2007.

i made a very important userform for my organisation using excel vba on a excel file , now i want to change the icon of this excel file.

Can i do it ?

i know we can do it but how i dont know..bcoz several times i downloaded "Sir J B7" answer sheet and those sheet's icon was not by default it was changed.

Any help will much appreciated.

regards
CA Mahaveer Somani
 
Thanks Narayan

i used this code but it does not changing my excel file icon. what i do?

Code:
Declare Function GetActiveWindow32 Lib "USER32" Alias _
"GetActiveWindow" () As Integer
 
Declare Function SendMessage32 Lib "USER32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
 
Declare Function ExtractIcon32 Lib "SHELL32.DLL" Alias _
"ExtractIconA" (ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
 
Dim hdlNewIcon As Long
Dim hdlXlMain As Long
 
Sub ChangeXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "C:WINDOWSMoricons.dll", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub
 
Sub RestoreXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "C:Program FilesMicrosoft OfficeOfficeexel.exe", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub
 
Hi Mahaveer ,

First , copy + paste the following code , instead of the code you have posted :
Code:
Declare Function GetActiveWindow32 Lib "USER32" Alias _
"GetActiveWindow" () As Integer
 
Declare Function SendMessage32 Lib "USER32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
 
Declare Function ExtractIcon32 Lib "SHELL32.DLL" Alias _
"ExtractIconA" (ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
 
Dim hdlNewIcon As Long
Dim hdlXlMain As Long
 
Sub ChangeXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "E:\WINDOWS\system32\Moricons.dll", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub
 
Sub RestoreXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "C:\Program Files\Microsoft Office\Office12\excel.exe", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub
The above code has to be posted in a module , which means you have to first insert a module in your VBE , and then paste the above code in that.

Second , verify that the paths to the two files viz. moricons.dll and excel.exe are the same as in your computer ; if not change them in the code.

The other change is that I have inserted the backslashes in the file path , which were not present in your posted code.

Narayan
 
Code:
Declare Function GetActiveWindow32 Lib "USER32" Alias _
"GetActiveWindow" () As Integer
 
Declare Function SendMessage32 Lib "USER32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
 
Declare Function ExtractIcon32 Lib "SHELL32.DLL" Alias _
"ExtractIconA" (ByVal hInst As Long, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Long) As Long
 
Dim hdlNewIcon As Long
Dim hdlXlMain As Long
 
Sub ChangeXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "C:\Windows\system32\moricons.dll", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub
 
Sub RestoreXLIcon()
 
hdlNewIcon = ExtractIcon32(0, "C:\Program Files(x86)\Microsoft Office\Office12\excel.exe", 1)
hdlXlMain = GetActiveWindow32()
 
SendMessage32 hdlXlMain, &H80, 1, hdlNewIcon 'Icon big
 
End Sub


i write the above code and then press ALT+F8 then i run ChangeXLIcon code but nothing happend.

is there any further process remaining after it....?
 
Hi Mahaveer ,

Have you gone through the associated link ? This will change the icon of the VBE while the file is open ; when you close the file , the original icon is restored.

To check this , when your file is open , press ALT TAB and cycle through the various programs and their icons.

Do this both before and after you run the macro , and see how the associated icon has changed.

To have a specific icon , you will have to change the parameter values to the ExtractIcon32 call and see how it changes.

Narayan
 
i m attaching my file in which the file "before" is seems as excel file

now i want to change the icon of "before" file which should looks like "after file"

is it possible or not for "before" file only. not for all excel file.....

i hope now you understand.
 

Attachments

  • i want to do like this.png
    i want to do like this.png
    19.8 KB · Views: 31
should i change some thing in that code?
i download the account.ico file
i changed the following only.

Code:
Sub Change_Icon()
setExcelIcon "D:\Excel\ico\account.ico"
End Sub

still not working.
 
Hi Mahaveer ,

The first answer to the question posted in the link says this :
Shannon,
My personal solution to this problem was to save all the spreadsheet in a folder (but could be different folders) then create shortcuts to these files in the desktop, then change the icon for the desktop shortcuts. It works pretty well and you can create your own icons using some existing icon designer tools.
Daniel

Narayan
 
Actually i m using EXCEL 2007.

i made a very important userform for my organisation using excel vba on a excel file , now i want to change the icon of this excel file.

Can i do it ?

i know we can do it but how i dont know..bcoz several times i downloaded "Sir J B7" answer sheet and those sheet's icon was not by default it was changed.

Any help will much appreciated.

regards
CA Mahaveer Somani
Hi, mahaveer!
I don't remember having done anything specific to change any icons, I think I always used the normal Excel icons. If you happened to found cases where I didn't, would you please post the links here so I could give a look at them?
Regards!
 
Back
Top