Results 1 to 15 of 15
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,437
    Thanks
    1
    Thanked 1 Time in 1 Post

    Using .GIF and .JPG files to make Button Images (VBA)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    Having some 11.2 Megabytes worth of .GIF image files, I thought of making them into images for buttons, most are already in 32x32 format, so that VBA applications can have their own customized toolbars with nice buttons is a better choice than dumping them into the Bit Recycler.

    Not that the ones that come with MS-Office are bad, but they are so ubiquitous, they lost their flare.

    So my question, is there a way I can place these images on buttons, and userforms easily, or what is the best technique to do this sort of thing? I looked at some MSKB articles and could not find any, so maybe my search keywords were not the best to use, so any suggestions will also be great.

    I promise I'll send you a copy of ALL the buttons that I generate.

    Thanks

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Office toolbars and menus (collectively, CommandBars) are very limited in this regard. There are CopyFace and PasteFace methods that you can use, but this puts the little graphic on the clipboard, which may annoy the user. (This is a common problem with Outlook Add-ins I've used.) I can't remember whether there are other ways to assign a graphic to a button, but you could try searching for threads that mention PasteFace and see if they lead anywhere.

    (P.S. Please don't send me any buttons. <img src=/S/wink.gif border=0 alt=wink width=15 height=15> )

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    I'll keep my buttons to myself then...
    <IMG SRC=http://www.city-and-guilds.co.uk/folder/cg_park_contents/photos/buttons.gif>

    StuartR

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Cool. I never even noticed the stdole library before. (Well, I noticed it there in the Object Browser but ignored it.)

    This help topic also seems to answer the not infrequent question of how to export CommandBar buttons to files. What a find!

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    I am interested in your pictures, how can I get hold of them?

    (Hope this is not going to be banned because of abusive language <bg>.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,437
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Andrew

    But where exactly did you get the code?

    I tried looking for it and I could not find in, <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    I need to look at what the <font color=blue>picButton</font color=blue> refer to.

    Thanks

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Andrew,

    That small piece of code is the answer to a number of problems that I have had over the years. I'm off to the object browser to see what else I can learn about stdole

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

    StuartR

    Edited by StuartR to fix multiple grammar and vocabulary errors. These 05:00 starts are starting to make me careless.

  8. #8
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,437
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Jefferson

    I thought that the <font color=blue>CopyFace</font color=blue> and <font color=blue>PasteFace</font color=blue> work with images on the buttons that come with MS-Office already and not images that are files on their own.

    So I will use Andrew's code snipit and possibly with the help of the FileSystemObject I'll make a list of all the files and their paths and generate the buttons this way.

    After I am satisfied with them, I'll publish them, but won't bother you with them as you requested.

    Thanks for the help.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  9. #9
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,437
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Jan Karel

    This is the least I could do, you have been a great help, and you do develop some neat apps, so I'll send you what I come up with, and here is what I am going to do:

    1) Wait for Andrew to send me a message about where he got the code from. I looked in the OLH and did not find it. I am using Excel 2003.

    2) Run his code with the help of the FileSystemObject and generate all these buttons. I may end up with 3000+, but then I'll clean them up because some images may not be appropriate.

    3) I'll send you the ToolBars in a workbook.

    Thanks agin.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Hi Wassim,

    < I need to look at what the picButton refer to >

    I'm glad you asked that, because there is an error in the code I posted ('tho I did copy it directly from Help). In testing it I corrected, but posted the Help version.

    Replace picButton with picPicture, which is the assigned object that holds the loaded image. Sorry about that.

    To locate the relevant Help page, go to the Object Browser, set the Libray to Office, search for button. You should see CommandBarButton in the list of classes. If you select that you should then see a list if items in the righthand pane which are the members of the CommandBarButton class. Select the Picture property and press F1. This should prersent you with the relevant help.

    Andrew

  11. #11
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,437
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Andrew

    I did the change, and it worked.

    I am writing the code to harvest all these images and get their paths and then your code will be used to generate all the images on to buttons.

    I'll be done next Tuesday. <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    That is perfect!

    I could do with the pic files and the code too, so I can use them directly to put them on Userform buttons too.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Image

    > I just took this code sample from VBA help :

    I took your code and added to it (attached, but requires some local-name customization)

    I seem to be in one two modes:
    (a) I need to autosave every 60 seconds because I'm on shaky ground, or keying in vast amounts of text
    ([img]/forums/images/smilies/cool.gif[/img] I want to maintain manual control over when a document/template is saved.

    Now I have a toolbar button that lets me flip-flop between "No AutoSave" and 'AutoSave every 60 secodns".

    Thanks!

  14. #14
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Jefferson,

    I just took this code sample from VBA help :

    Sub ChangeButtonImage()
    Dim picPicture As IPictureDisp
    Dim picMask As IPictureDisp

    Set picPicture = stdole.StdFunctions.LoadPicture( _
    "c:imagespicture.bmp")
    Set picMask = stdole.StdFunctions.LoadPicture( _
    "c:imagesmask.bmp")

    'Reference the first button on the first command bar
    'using a With...End With block.
    With Application.CommandBars.FindControl(msoControlButt on)
    'Change the button image.
    .Picture = picButton

    'Use the second image to define the area of the
    'button that should be transparent.
    .Mask = picMask
    End With
    End Sub

    It allows changing a button image from an image file. I tried it with a Gif image and it worked.

    Take a look at help for CommandBarButton , Picture Property

    Andrew C

  15. #15
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,924
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using .GIF and .JPG files to make Button Images (VBA)

    Hi Wassim

    I am fascinated by this post, I think I know what's happening is possible to post a sample file showing the result you are trying to get.

    Many Thanks

    Braddy
    If you are a fool at forty, you will always be a fool

Posting Permissions

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