+ Reply to Thread
Results 1 to 17 of 17

Change File Icon and/or Title Bar Icon

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2011
    Location
    Washington, OK
    MS-Off Ver
    Office 2010
    Posts
    23

    Change File Icon and/or Title Bar Icon

    Hi all,

    I have searching furiously all morning and have had no luck finding a code to work properly.

    I am trying to create a real "program feel" to the project I am working on, and want to know if it even possible to use my own icon that i have created. I have relocated the file to
    "C:\Windows\System32\LabTech1.ico", but can relocate if needed.

    I have been able to make one code change the Title Bar Icon to Notepad (but I have to assume that is considered childs play to most of you at this point), and I tried fruitlessly to modify it to suit my needs.
    Casey Wells

    Most Appreciative Rookie!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change File Icon and/or Title Bar Icon

    Hello Casedias,

    This macro will change the icon for Excel 2003 using an icon from a file. This may require some changes if you are using this with excel 2007 or 2010. If you are not changing the Excel icon then this macro will be need to changed to work with any Windows window.

    Copy and paste this code into a new VBA module in your workbook's VBA project.
    'Written: March 29, 2011
    'Author:  Leith Ross
    
    'Constants
     Const IMAGE_ICON As Long = &H1
     Const WM_SETICON As Long = &H80
     Const ICON_BIG As Long = &H1
    
    'Constants for Load Image's fuLoad Parameter (Load Resource)
     Const LR_DEFAULTCOLOR As Long = &H0
     Const LR_MONOCHROME As Long = &H1
     Const LR_COLOR As Long = &H2
     Const LR_COPYRETURNORG As Long = &H4
     Const LR_COPYDELETEORG As Long = &H8
     Const LR_LOADFROMFILE As Long = &H10
     Const LR_LOADTRANSPARENT As Long = &H20
     Const LR_DEFAULTSIZE As Long = &H40
     Const LR_VGACOLOR As Long = &H80
     Const LR_LOADMAP3DCOLORS As Long = &H1000
     Const LR_CREATEDIBSECTION As Long = &H2000
     Const LR_COPYFROMRESOURCE As Long = &H4000
     Const LR_SHARED As Long = &H8000
    
    'Returns an Icon from a File (.ico)
     Private Declare Function LoadImage _
       Lib "user32.dll" Alias "LoadImageA" _
         (ByVal hInst As Long, _
          ByVal lpsz As String, _
          ByVal uType As Long, _
          ByVal cxDesired As Long, _
          ByVal cyDesired As Long, _
          ByVal fuLoad As Long) _
       As Long
    
    'Direct System what to do with the Window
     Private Declare Function SendMessage _
       Lib "user32.dll" Alias "SendMessageA" _
         (ByVal hWnd As Long, _
          ByVal wMsg As Long, _
          ByVal wParam As Long, _
          lParam As Long) _
       As Long
    
    'Redraw the Icons on the Window's Title Bar
     Private Declare Function DrawMenuBar _
       Lib "user32.dll" _
         (ByVal hWnd As Long) _
       As Long
    
    
    Public Function ChangeExcelIcon(ByVal Icon_File_Path As String)
    
      Dim hWnd As Long
      Dim hIcon As Long
      Dim LoadMask As Long
    
        hWnd = Application.hWnd
        LoadMask = LR_LOADFROMFILE Or LR_DEFAULTSIZE Or LR_SHARED
        hIcon = LoadImage(0&, Icon_File_Path, IMAGE_ICON, 32, 32, LoadMask)
    
        Call SendMessage(hWnd, WM_SETICON, ICON_BIG, ByVal hIcon)
        Call DrawMenuBar(hWnd)
    
    End Function

    Example of Using th Macro
    Sub IconTest()
    
      ChangeExcelIcon "C:\Documents and Settings\Admin.ADMINS\My Documents\Properties 16.ico"
      
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    09-15-2011
    Location
    Washington, OK
    MS-Off Ver
    Office 2010
    Posts
    23

    Re: Change File Icon and/or Title Bar Icon

    Leith,

    This didn't work either; so before continuing, I want to ensure I performed this properly.

    I copied/pasted your first code string into a new module.
    I then copied/pasted your sub below it.

    The only change I made to either code was to change the destination to my .ico file: "C:\Windows\System32\LabTech1.ico"

    I then tried to run the macro, but had no luck. It ran with no errors, but did nothing.

    Have I done something wrong? I do not know what I would have to change from 2003 to 2007/10.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change File Icon and/or Title Bar Icon

    Hello Casedias,

    I am surprised you didn't receive any errors if it failed to do anything. I would expect it to either work or throw an error. Is this file an Excel workbook?

  5. #5
    Registered User
    Join Date
    09-15-2011
    Location
    Washington, OK
    MS-Off Ver
    Office 2010
    Posts
    23

    Re: Change File Icon and/or Title Bar Icon

    Yes, Building it on my laptop running Excel 2010, but I pasted your code into a new blank workbook. I am also at a loss, since all other codes I have tried caused errors.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change File Icon and/or Title Bar Icon

    Hello Casedias,

    I am guessing you are running Windows 7 32 bit platform. If it 64 bit then should have been errors in the API code. I will have to research this further to find an answer.

  7. #7
    Registered User
    Join Date
    09-15-2011
    Location
    Washington, OK
    MS-Off Ver
    Office 2010
    Posts
    23

    Re: Change File Icon and/or Title Bar Icon

    For developmental ease I have them set to enabel all, but just to test I set them to disable with notification. No change.

+ 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