Results 1 to 6 of 6

Thread: Deactivate button after it has been run once

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    Location
    Another way --

    in Signatures ...

    Option Explicit
    Public oRibbon As IRibbonUI
    Public bBeenRun As Boolean
    
    'Callback for customUI.onLoad
    Public Sub Ribbon_OnLoad(ribbon As IRibbonUI)
        Set oRibbon = ribbon
        bBeenRun = False
    End Sub
    
    
    'Callback for HLR_PageSetup getEnabled
    Sub AlreadyRun(control As IRibbonControl, ByRef returnedVal)
        returnedVal = Not bBeenRun
    End Sub
    
    
    'Callback for HLR_PageSetup getScreentip
    Sub PageSetupTip(control As IRibbonControl, ByRef returnedVal)
        Dim b As Boolean
        Call AlreadyRun(control, b)
        returnedVal = IIf(b, "Click to run PageSetup", "PageSetup can only be run once")
    End Sub


    In PageSetup


    'Callback for 'HLR Page Setup' onAction
    Sub rxbtnHLR_PageSetup_click(control As IRibbonControl)
      
        bBeenRun = True
        oRibbon.InvalidateControl ("HLR_PageSetup")
      
        Call HLR_PageSetup
        MsgBox "pagesetup run"
    End Sub

    Tweak to the CustomUI XML to use getEnabled and getScreentip callbacks

        <button
            id="HLR_PageSetup"
            label="Page Setup"
            showLabel="false"
            size="large"
            image="HLR-32x32"
            onAction="rxbtnHLR_PageSetup_click"
            description="HLR Page Setup"
            getEnabled = "AlreadyRun"
            getScreentip="PageSetupTip"
            supertip="Formats page view, insert signature of user and inserts the current date."/>
    I attached my effort, but rename off the .zip part if you want to see it

    You can 'program around' the Boolean flag, I use things like that to keep things obvious (I get myself into trouble when I try to be TOO clever)
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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