Master pivot tables, formulas and more with video courses from industry experts. Find resources for Office development, including code samples, events, blog posts, and more. This site uses cookies for analytics, personalized content and ads. By continuing to.
I found a lot of nice icons from Microsoft Office 2007. Do you any idea for extract & save all icons as PNG files by using VBA?
The following code is code which is used to get image from ImageMSO.
I can display all as PictureBox control and save excel file as web page. However, every icons is very low quality.
Moreover, I try to create C# Excel Add-in project for exporting as Bitmap object by using the following code. But I found that it can't export as semi-transparent PNG.
PS. I want to save all icons as PNG format because I need to use semi-transparent feature of it. It allow me to use all icons on most background color more than white background.
Soul_MasterSoul_Master
4 Answers
I use ImageMso quite frequently in my Excel development. Having stumbled on this post, I took it a step further and put a package together to visually search, extract and save icons from Microsoft Excel as a file or copy and paste (with alpha channel transparency) to another application. I also compiled a list of 8,899 distinct ImageMso names from the various sources. I hope others can find this useful.
Alton XLAlton XL
I've wrapped up a C# Utility class for extracting Office2007 gallery icons to .png files, while maintaining their transparency properly. The main code is taken from a great article written by Andrew Whitechapel (http://blogs.msdn.com/b/andreww/archive/2007/10/10/preserving-the-alpha-channel-when-converting-images.aspx). I've integrated this with the Office 2007 sample icon sheet, in case you want to extract all of these icons to a target folder.
Steps are:
1) Download the Office Gallery spreadsheet at http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=11675
2) Call OfficeIcons.ExtractAllIcons() with the location of the Office2007IconsGallery.xlsm sample spreadsheet, and the target folder where you want the icons extracted.
{code}
{code}
Ismail DeganiIsmail Degani
All of the PNG files can be found here These are all in PNG format already. Good programming! (a nice ZIP archive is also available Here) The ZIP archive contains all 17 of the Excel icons.
When you use the GetImageMso method, you end up with an IPicture interface to the object. The IPicture interface accesses the icon suitable for saving to a file in the original format - an .ICO, .WMF or a .BMP The PNG format is not supported. The following links explain why this is not directly possible:
http://msdn.microsoft.com/en-us/library/aa434604.aspx (msoGetImageMso method)http://msdn.microsoft.com/en-us/library/ms680761%28VS.85%29.aspx (IPicture Interface)http://msdn.microsoft.com/en-us/library/ms694504%28VS.85%29.aspx (Save As File method)
However, using a more complex approach will yield what you want:
cavingcaving
![Gallery Gallery](https://support.content.office.net/en-us/media/8661180b-9163-4a9b-abe4-653347abf5c0.png)
I have tried Ismail's answer and it did work great. However it took me a while to figure out how to make it work. I may share this bit of knowledge:
The solution requires ExcelDna from codeplex: link.
As I am using
Net 4.0
I do not have .zip support so I first extracted the .xslm files to a flat directory structure then I changed the code to read directly from the files.Then in the Excel I call the ExcelDna extension method as ![Office Office](/uploads/1/2/5/2/125260211/564201017.png)
The using statements for the utility class (for me):
Hope this helps.... Thank you Ismail!
gbrgbr