Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

word vba to set folder icon

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeB77 - 29 Dec 2007 00:59 GMT
Hello
I'm having trouble reliably setting the icon of a new folder that I generate
with filesystemobject.  Once I've made a new folder (named 'fldName'), I want
to set its icon.  I can do this by adding a desktop.ini file within the
folder:

Dim fs
Set fs = CreateObject("scripting.filesystemobject")
Set getMyRecentPathsFld = fs.createfolder(fldName) 'returns the folder from
my function
FName = fldName & "\Desktop.ini"
System.PrivateProfileString(FName, ".ShellClassInfo", "IconFile") =
"%SystemRoot%\system32\SHELL32.dll"
System.PrivateProfileString(FName, ".ShellClassInfo", "IconIndex") = 155

This generates a desktop.ini as desired.  BUT the folder's icon doesn't
change with this code until I first change it manually (via properties...),
after which it works fine.  If the folder icon has not been changed manually
the new desktop.ini file looks fine but the icon does not change.  I don't
understand why.

Am I missing something here, like some way of telling the folder to look for
a desktop.ini? Or is there a better way?

Thanks in advance
Mike
Steve Yandl - 29 Dec 2007 04:49 GMT
Mike,

It's been some time since I've set up a routine to change folder icons but
in the somewhat distant past I have used the "Scripting.FileSystemObject" to
create a new text file named desktop.ini, used FSO to insert the correct
lines and then used cmd.exe to change the attributes of desktop.ini to
hidden and system.  I still recall having to select the new folder and press
F5 to refresh Explorer to get the change to take effect.  It might make your
users angry but you could probably kill the Explorer.exe process and restart
it to have the change of folder icon take effect.

My choice these days is to create a new folder where I stash all my created
new folders and place a shortcut to that folder on the user's desktop.
Icons for shortcuts are a lot simpler to edit than icons for the folder
object.

Steve

> Hello
> I'm having trouble reliably setting the icon of a new folder that I
[quoted text clipped - 28 lines]
> Thanks in advance
> Mike
MikeB77 - 29 Dec 2007 08:25 GMT
Steve
File attributes - the missing step!  I looked at the attributes of folders
(with getAttr) I had set manually then added the following to the code above.
It now changes the icon of the newly created folder:

SetAttr fldName, vbReadOnly ' thats my new folder
SetAttr FName, vbHidden + vbSystem + vbArchive ' thats my 'desktop.ini'
created by System.PrivateProfileString

Thanks Steve for another great tip and more hours of sleep saved.

Mike

> Mike,
>
[quoted text clipped - 13 lines]
>
> Steve

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.