+ Reply to Thread
Results 1 to 16 of 16

Changing the .ico icon of my excel file?

Hybrid View

  1. #1
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Changing the .ico icon of my excel file?

    I would like to change the icon of my workbook to a different .ico file than the excel icon. I have already created the icon image file, and located here:

    G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico

    Is there a way to change the icon for my excel workbook without it affecting other excel workbooks unrelated to my project?
    Last edited by jonvanwyk; 03-29-2011 at 02:23 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Changing the .ico icon of my excel file?

    The icon on the workbook corner?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    I hadn't thought of that one...but sure...that one too. My original thought was the icon that the person double clicks on to open the workbook to begin with (or any subsequent shortcuts someone might make to their original timesheet file).

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Changing the .ico icon of my excel file?

    This code creates a Desktop icon

    
    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 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()
        setExcelIcon "G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico"
    End Sub
    
    Sub Reset_Icons()
        setExcelIcon ""
    End Sub

  5. #5
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    I cant get it to work yet. I imagine I might be putting the code in the wrong place. Does it just go into a module?

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Changing the .ico icon of my excel file?

    I've never used that code, simply found it some time ago & stored in my code library.

    I've come up with this that works

    
    '---------------------------------------------------------------------------------------
    ' Module    : mAddRemoveShortcut
    ' Author    : user
    ' Website   : for more examples and Excel Consulting
    ' Date      : 26/03/2011
    ' Purpose   : Add and remove desktop icon to active workbook
    '---------------------------------------------------------------------------------------
    
    
    Option Explicit
    
    
    Sub CreateDesktopShortcut()
        Dim WSHShell As Object
        Dim MyShortcut As Object
        Dim DesktopPath As String
        Set WSHShell = CreateObject("WScript.Shell")
        DesktopPath = WSHShell.SpecialFolders("Desktop")
        Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\" & _
                                                 ThisWorkbook.Name & ".lnk")
        With MyShortcut
            .TargetPath = ThisWorkbook.FullName
            .IconLocation = "G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico"
            .Save
        End With
        Set WSHShell = Nothing
        MsgBox "A shortcut to " & ThisWorkbook.Name & " has been placed on your desktop.", vbInformation, "Success"
    End Sub
    
    Sub DeleteDesktopShortcut()
        Dim WSHShell As Object
        Dim MyShortcut As Object
        Dim DesktopPath As String
        Set WSHShell = CreateObject("WScript.Shell")
        DesktopPath = WSHShell.SpecialFolders("Desktop")
        On Error GoTo NotFound
        Kill (DesktopPath & "\" & ThisWorkbook.Name & ".lnk")
        MsgBox "The shortcut has been removed from your desktop.", vbInformation, "Success"
        Set WSHShell = Nothing
        Exit Sub
    NotFound:
        MsgBox "A shortcut to the " & ThisWorkbook.Name & " was not found on your desktop.", vbCritical, "Aborted"
        Set WSHShell = Nothing
    End Sub

  7. #7
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    @royUK ... I know you are an excel genius, so I am going to blame the fact I cant get your latest solution to work on my own ineptitude. Does it matter that the "G:\" drive is not my workstation's local harddrive? "G"\" is a shared drive on our intranet from which all of the timesheet workbooks will be opened. Like most of the planet, "C:\" is my local drive...but if I used that I would have to add the .ico file to every workstation in the department.

    Also, is the code supposed to go into a module, or into "ThisWorkbook" on the VBE? Thanks again for all of your help!

  8. #8
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    I realized that there was more that I had to change in the code royUK suggested. I have made the changes to the best of my ability, but my special icon is still not working :-( Any idea what I am doing wrong?


    
    Option Explicit
    
    
    Sub CreateDesktopShortcut()
        Dim WSHShell As Object
        Dim MyShortcut As Object
        Dim DesktopPath As String
        Set WSHShell = CreateObject("WScript.Shell")
        DesktopPath = WSHShell.SpecialFolders("Desktop")
        Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "C:\Users\jmv\Desktop\" & _
                                                 ThisWorkbook.Name & "G:\Timesheets\FY2011\Communications\FY2011 Timesheet Template.lnk")
        With MyShortcut
            .TargetPath = ThisWorkbook.FullName
            .IconLocation = "G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico"
            .Save
        End With
        Set WSHShell = Nothing
        MsgBox "A shortcut to " & ThisWorkbook.Name & " has been placed on your desktop.", vbInformation, "Success"
    End Sub
    
    Sub DeleteDesktopShortcut()
        Dim WSHShell As Object
        Dim MyShortcut As Object
        Dim DesktopPath As String
        Set WSHShell = CreateObject("WScript.Shell")
        DesktopPath = WSHShell.SpecialFolders("Desktop")
        On Error GoTo NotFound
        Kill (DesktopPath & "C:\Users\jmv\Desktop\" & ThisWorkbook.Name & "G:\Timesheets\FY2011\Communications\FY2011 Timesheet Template.lnk")
        MsgBox "The shortcut has been removed from your desktop.", vbInformation, "Success"
        Set WSHShell = Nothing
        Exit Sub
    NotFound:
        MsgBox "A shortcut to the " & ThisWorkbook.Name & " was not found on your desktop.", vbCritical, "Aborted"
        Set WSHShell = Nothing
    End Sub

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing the .ico icon of my excel file?

    This creates a shortcut of the file
    E:\example.xls
    In folder C:\

    Sub snb()
      With CreateObject("WScript.Shell").CreateShortCut("C:\example.xls.lnk")
        .targetpath = "E:\example.xls"
        .iconlocation="G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico"
        .Save
      End With
    End Sub
    If you can't get it to work (after adaptation) in your situation please tell us:
    - the location and the filename you want to make a shortcut for
    - the location where the shortcut must be put.
    Last edited by snb; 03-29-2011 at 04:04 AM.



  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Changing the .ico icon of my excel file?

    You could try putting the icon in the same location as the workbook, then use ThisWorkBook.Path

  11. #11
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    The location of everything is:

    C:\Users\jmv\Desktop\

    G:\Timesheets\FY2011\Communications\FY2011 Timesheet Template.xlsb

    G:\Timesheets\PDF Archive\Miscellaneous\scsobadgeicon01.ico

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing the .ico icon of my excel file?

    Sub snb()
      With CreateObject("WScript.Shell").CreateShortCut("C:\Users\jmv\Desktop\FY2011 Timesheet Template.xlsb.lnk")
        .targetpath = "G:\Timesheets\FY2011\Communications\FY2011 Timesheet Template.xlsb"
        .iconlocation="G:\Timesheets\PDF_Archive\Miscellaneous\scsobadgeicon01.ico"
        .Save
      End With
    End Sub
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by snb; 03-30-2011 at 08:48 AM.

  13. #13
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    @snb...forgive my ignorance. Do I use the code you just mentioned alone and in place of the code that royUK made, or is it meant to be used in addition to his code? (I tried using just yours and it did no do anything.)

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Changing the .ico icon of my excel file?

    I've "borrowed" an icon, put in the same folder as the workbook & amended the code
    Attached Files Attached Files

  15. #15
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    royUK...

    I am sorry for being so dense today. Is it Friday yet? I unzipped the folder and put it on my desktop. What now? Was the excel file icon supposed to mirror the .ico file? It didn't (see attached)...I am sure it is my fault. :-/

    Update: Also...when refering to a file located on the computer that has spaces (such as "FY2011 Timesheet Template"), does one need to use underscores in place of the spaces?
    Attached Images Attached Images
    Last edited by jonvanwyk; 03-29-2011 at 11:07 AM.

  16. #16
    Forum Contributor jonvanwyk's Avatar
    Join Date
    06-28-2010
    Location
    Iowa, USA
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: Changing the .ico icon of my excel file?

    After playing around with your guys' code a bit, I managed to get something to work (seen below). I inserted snb's code into the Workbook_BeforeClose command of the "ThisWorkbook" code. The user has to go through all of the folders to get to their timesheet only once, and then it creates the shortcut with the cusomised .ico file when the document is closed. They have to open it the hard way once on each workstation. I am satisifed with this solution.

    
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
    Application.DisplayStatusBar = True
    
      With CreateObject("WScript.Shell").CreateShortCut("C:\Users\jmv\Desktop\FY2011 Timesheet Template.lnk")
        .targetpath = "G:\Timesheets\FY2011\Communications\FY2011 Timesheet Template.xlsb"
        .iconlocation = "G:\Timesheets\PDF Archive\Miscellaneous\timesheeticon.ico"
        .Save
      End With
    
    End Sub
    
    Private Sub Workbook_Deactivate()
    Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",True)"
    Application.DisplayStatusBar = True
    End Sub
    
    Private Sub Workbook_Activate()
    Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
    Application.DisplayStatusBar = True
    End Sub
    
    Private Sub Workbook_Open()
    Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
    Application.DisplayFormulaBar = False
    Worksheets("Menu").Select
    Application.DisplayStatusBar = False
     
    End Sub
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",False)"
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    If IsNumeric(Sh.Name) Then
    Sh.ScrollArea = "A1:O30"
    Else
    Sh.ScrollArea = "A1:M12"
    End If
    End Sub
    Last edited by jonvanwyk; 03-29-2011 at 02:23 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1