+ Reply to Thread
Results 1 to 14 of 14

Excel VBA: USERFORM simulate button click on image

Hybrid View

ironfelix717 Excel VBA: USERFORM simulate... 08-28-2018, 10:38 PM
Logit Re: Excel VBA: USERFORM... 08-28-2018, 11:35 PM
Logit Re: Excel VBA: USERFORM... 08-28-2018, 11:45 PM
ironfelix717 Re: Excel VBA: USERFORM... 08-29-2018, 09:10 PM
Logit Re: Excel VBA: USERFORM... 08-29-2018, 11:32 PM
romperstomper Re: Excel VBA: USERFORM... 08-30-2018, 01:41 AM
Andy Pope Re: Excel VBA: USERFORM... 08-30-2018, 04:43 AM
ironfelix717 Re: Excel VBA: USERFORM... 08-30-2018, 08:54 PM
romperstomper Re: Excel VBA: USERFORM... 08-31-2018, 10:07 AM
ironfelix717 Re: Excel VBA: USERFORM... 08-31-2018, 12:56 PM
JayM101 Re: Excel VBA: USERFORM... 04-30-2021, 12:33 PM
DanNatCorning Re: Excel VBA: USERFORM... 10-20-2022, 06:57 PM
FDibbins Re: Excel VBA: USERFORM... 10-21-2022, 12:44 AM
JayM101 Re: Excel VBA: USERFORM... 10-21-2022, 07:16 AM
  1. #1
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Excel VBA: USERFORM simulate button click on image

    Hi all.

    VBA has the ugliest UI options, no news to us there. I am looking to create rounded buttons. And the only way to solve this without getting hardcore into API is using shapes (spreadsheet) or images (userform).

    Thats great... If you want your button to not actuate. At that point i would rather just use an ugly Windows 95 button than a shape that doesn't... click. The point of a button is to actuate. To press and depress.

    One source provided a great method for shape buttons (worksheets), where he flashes the button on click. Though I haven't tried it personally.
    See here: https://wellsr.com/vba/2015/excel/si...ctangle-shape/


    Still, that doesn't solve the issue with forms because shapes are not a form control. Cool, we can use an image. The button will actuate with an image on it. The problem here is the truly genius software designers at Microsoft decided to not allow a transparent border command button border property. Actually, there is no 'border' property at all. So now this entire method is a waste. Regardless of how much time you take to design the perfect button with your favorite online button generator or in photoshop, your time will be wasted.

    Which leaves me to resulting to the forum for questions... Has anyone been able to design some sort of sequence using mutiple images where a series of custom buttons (userform image control) simulates a single button pressed and depressed? This would be the userform/image equivalent to what the guy has done above. If not, where might i start? I am good with photoshop and graphic design so no issues there.


    Thank you

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,405

    Re: Excel VBA: USERFORM simulate button click on image

    .
    This may be one way of accomplishing the goal :

    Private Sub ToggleButton1_Click()
     
     Dim name As String
     
     If ToggleButton1.Value = True Then
         Label1.Caption = "GO Clicked"
        name = "Picture 1"
     ElseIf ToggleButton1.Value = False Then
        Label1.Caption = "GO Unclicked"
        name = "Picture 2"
     End If
    
        Worksheets("Sheet1").Shapes(name).CopyPicture xlScreen, xlBitmap
        Set ToggleButton1.Picture = PastePicture(xlBitmap)
    End Sub
    There is more code within the workbook that is too lengthy to post here.
    Attached Files Attached Files

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,405

    Re: Excel VBA: USERFORM simulate button click on image

    .
    Some other idea :

    https://www.youtube.com/watch?v=UTFnERi9T30

  4. #4
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: Excel VBA: USERFORM simulate button click on image

    Logit,

    Thanks for the reply. The example workbook isn't what I am looking for. It still has a border around the image because its an image placed on a button.

    As for the video, he doesn't explain anything about actually creating a button with images/code. He just messed with those sheep images.

    I've made a quick attempt with:

    Private Sub Image2_Click()
    Image2.SpecialEffect = fmSpecialEffectFlat
    End Sub
    But i don't really know how to change it back to fm_specialEffectRaised or whatever when the mouse click is released. Is there really not an event for mouse pointer being held?

    Welcoming more ideas for anyone who has attempted to make a button work just like a command button from an image.

    Thanks for your help.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,405

    Re: Excel VBA: USERFORM simulate button click on image

    .
    Other suggestions :

    https://wellsr.com/vba/2015/excel/si...ctangle-shape/



    Here is something else :

    Sub TogglePicSize()
        Dim shp As Shape
         Set shp = ActiveSheet.Shapes(Picture2)
        With shp
            .LockAspectRatio = msoTrue
            If .Width = 75 Then .Width = 80 Else .Width = 75
        End With
    End Sub
    Maybe you can edit the image to meet your expectations.
    Attached Files Attached Files

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel VBA: USERFORM simulate button click on image

    Have you tried using the MouseDown/MouseUp events?
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Excel VBA: USERFORM simulate button click on image

    As rorya suggests make use of the mouse events.

    If you want to include text on the button then remember to offset that down/right slightly on the down image.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: Excel VBA: USERFORM simulate button click on image

    Hi All,

    I guess I was misinterpreting what the MouseDown/Up events actually are. I didn't realize they are what I want!

    So, I made two buttons and changed the images and some code (see attached). Works awesome!!

    Two issues persist: 1) How do I get the background image in a .GIF to be transparent? Since microsoft doesn't allow PNGs (another great work of the geniuses at MS), what are my options for image formats that supports transparency AND HIGH QUALITY ?
    EDIT: I had not realized .GIF format supports transparency. This question solved.



    Lasty, 2) This works great but performance is rather sluggish. I think I already know the answer to this question. I assume there's no way to improve the responsiveness of the "button" after consecutive events?

    Thanks for everyones help and time.
    Attached Files Attached Files
    Last edited by ironfelix717; 08-30-2018 at 09:10 PM.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Excel VBA: USERFORM simulate button click on image

    Quote Originally Posted by ironfelix717 View Post
    another great work of the geniuses at MS
    A couple of small observations:
    1. I bet that if I picked apart a program you made 20 years ago I could probably make fun of your decisions too with the benefit of a lot of hindsight. (Now if you want to mock their decision not to support VBA properly, I'll join you. )
    2. I personally (and I know this is true of others) am put off answering questions by people who complain about the tools all the time. Just something you may want to consider. Or not. Entirely up to you. But I pretty much guarantee those programmers were smarter than you or me.

  10. #10
    Forum Contributor
    Join Date
    08-22-2017
    Location
    USA
    MS-Off Ver
    2016 WINDOWS and MAC
    Posts
    294

    Re: Excel VBA: USERFORM simulate button click on image

    Quote Originally Posted by rorya View Post
    A couple of small observations:
    1. I bet that if I picked apart a program you made 20 years ago I could probably make fun of your decisions too with the benefit of a lot of hindsight. (Now if you want to mock their decision not to support VBA properly, I'll join you. )

    2. I personally (and I know this is true of others) am put off answering questions by people who complain about the tools all the time. Just something you may want to consider. Or not. Entirely up to you. But I pretty much guarantee those programmers were smarter than you or me.
    Oh, no dispute there on your guarantee they are and were smarter than us. I mean, office developers probably don't need to rely on the Excel Forum for questions on basic programming tasks like I do

    However, mocking their lack of support is no more right, wrong, or indifferent than complaints of their (lack of) tools. Regardless, both aren't suited for this thread. I'll try to bite my tongue in the future.

    Thanks

  11. #11
    Registered User
    Join Date
    01-31-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016
    Posts
    4

    Re: Excel VBA: USERFORM simulate button click on image

    Hello Everyone,

    I know this thread is a few years old but I also needed an Image on a Userform to appear as a button.

    This is how I solved it.

    Firstly, when you create the Image on the Userform, in the properties window of the Image, set the SpecialEffect to 'fmSpecialEffectRaised'

    Next simulate the click
    Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Me.Image1.SpecialEffect = fmSpecialEffectFlat
    Me.Image1.BorderStyle = fmBorderStyleSingle
    
    End Sub
    Private Sub Image1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Me.Image1.SpecialEffect = fmSpecialEffectRaised
    
    End Sub
    Finally, the actual Click event
    Private Sub Image1_Click()
    
    Debug.Print "Image Clicked"
    
    End Sub

  12. #12
    Registered User
    Join Date
    08-07-2012
    Location
    Corning, NY
    MS-Off Ver
    Office 365
    Posts
    4

    Re: Excel VBA: USERFORM simulate button click on image

    Jay, I'm not sure exactly how your code would work since there is no Click event for an image. Care to elaborate?

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Excel VBA: USERFORM simulate button click on image

    Quote Originally Posted by DanNatCorning View Post
    Jay, I'm not sure exactly how your code would work since there is no Click event for an image. Care to elaborate?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  14. #14
    Registered User
    Join Date
    01-31-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016
    Posts
    4

    Re: Excel VBA: USERFORM simulate button click on image

    Hi DanNatCorning, agreed there is no Click event available from the drop down menu, but if you manually type it, it works perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel UserForm. Click Button to open explorer and go to URL within a text box
    By stevefisher85 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-19-2016, 06:09 AM
  2. Button Click on Spreadsheet commanded by Button Click on Userform
    By Quilie19 in forum Excel Programming / VBA / Macros
    Replies: 33
    Last Post: 04-07-2015, 11:35 PM
  3. [SOLVED] Navigating IE via VBA, click on specific image/button
    By Skybeau in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2014, 06:29 PM
  4. Are there any experts in Excel out there? Trying to simulate a physical double click
    By eugeneaeria in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2014, 07:10 PM
  5. Replies: 2
    Last Post: 01-30-2014, 07:52 PM
  6. Show Monthview via Image Click in Userform
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2013, 11:55 AM
  7. Code a Command Button on UserForm not to close upon click - Excel VBA
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-14-2012, 02:20 PM

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