where to place code

shaker

Board Regular
Joined
Jul 19, 2002
Messages
88
Hi every one
i copied this formula of the board to use to change excel icons

it might seem a silly question but i only a bigenner. where do i paste it do i put this one in "this workbook" of vba?

Option Explicit

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

Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0
Private Const ICON_BIG = 1

Sub setExcelIcon(Optional strFileName 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 strFileName = "" Then
strIconIndex = 8000
hIcon = ExtractIcon(0, Application.Path & Application.PathSeparator & "Excel.exe", strIconIndex)
ElseIf Dir(strFileName) = "" Then
hIcon = 0
ElseIf Err.Number <> 0 Then
hIcon = 0
Else
hIcon = ExtractIcon(0, strFileName, strIconIndex)
End If

'Set the big (32x32) and small (16x16) icons
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()
setExcelIcon "c:ProgramFilesIconsarrows2.ico"
End Sub

Sub Restore()
setExcelIcon ""
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi shaker,

This code should go into a standard macro module (keyboard Alt-TMV to get to VBE, then Alt-IM to insert a new macro module, then paste the code into the code pane).
 
Upvote 0
Thnx Damon
Did that just now doesn't seem to change icon.. is there any thing else i must do? write in in "this workbook" etc
thnx in advance
This message was edited by shaker on 2002-11-02 02:43
 
Upvote 0
The code uses the system shell. You need to set Excel's reference. In the VB editor toolbar select "Tools - References" check:
Visual Basic for Applications
Microsoft Excel object Library
OLE Automation
Microsoft Office object library

These may fix the problem, I don't know which of these the Shell library is in, but if you set these references you should be covered? JSW
 
Upvote 0
How are you executing the "Change" and "Restore" procedures? From a command button, an event, or what?

Try going to the immediate pane of VBA (View > Immediate Window) and type "Change".

You can also step thru the macro: click inside the "Change" Sub. and then press F8 repeatedly. You may then get some clues as to where its going wrong.
This message was edited by Swamp Thing on 2002-11-02 20:37
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,238
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top