Consulting

Results 1 to 9 of 9

Thread: Solved: simulating CorelDraw or Photoshop functionality

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Solved: simulating CorelDraw or Photoshop functionality

    I made a form modeless thinking I could simulate something like a photoshop toolbar for my macros. It basically consists of a textbox and 8 different buttons for similar macros that move shapes around. The thing is, it's not acting exactly as I expected:

    1) Anything I do is noted as ONE action until the focus goes back to the document, so when I UNDO, it undoes EVERYTHING instead of the last button clicked.

    Is that the way it's supposed to behave? If so, how does one make it behave like a normal toolbar in Photoshop or CorelDraw? I'm sure it's probably just a property I have set wrong in my form or something.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Ok, let me put it another way. Maybe that will help.

    Is it possible to have just a textbox in a userform to pass along a variable to various macros I have? No close button; I plan to keep the form up all the time like a toolbar.

    ...or can i have a textbox in a toolbar like photoshop?

    ... or is there a better way?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Here's some code for an Add-In that builds a toolbar with an edit control and some buttons to give you an idea.[VBA]Sub Auto_Open()
    BuildToolbar
    End Sub

    Sub Auto_Close()
    DeleteToolBar
    End Sub

    Private Sub BuildToolbar()

    Dim TBar As CommandBar
    Dim btnNew As CommandBarControl
    'Dim btnPop As CommandBarControl

    DeleteToolBar
    Set TBar = CommandBars.Add(Name:="My Custom Toolbar")
    With TBar
    Set btnNew = .Controls.Add(Type:=msoControlButton)
    With btnNew
    .Caption = "Command 1"
    .Style = msoButtonCaption
    .OnAction = "ControlRoutine" 'below
    End With
    Set btnNew = .Controls.Add(Type:=msoControlButton)
    With btnNew
    .Caption = "Command 2"
    .Style = msoButtonCaption
    .OnAction = "ControlRoutine" 'below
    End With
    Set btnNew = .Controls.Add(Type:=msoControlButton)
    With btnNew
    .Caption = "Command 3"
    .Style = msoButtonCaption
    .OnAction = "ControlRoutine" 'below
    End With
    Set btnNew = .Controls.Add(Type:=msoControlEdit)
    With btnNew
    .BeginGroup = True
    End With
    .Visible = True
    End With


    End Sub

    Private Sub DeleteToolBar()
    Dim TBar As CommandBar
    For Each TBar In Application.CommandBars
    If TBar.Name = "My Custom Toolbar" Then TBar.Delete
    Next
    End Sub

    Sub ControlRoutine()

    Dim ctrlEdit As CommandBarControl
    Dim myVal As String

    Set ctrlEdit = CommandBars("My Custom Toolbar").FindControl( _
    Type:=msoControlEdit)
    If Not ctrlEdit Is Nothing Then
    If ctrlEdit.Text <> "" Then
    myVal = ctrlEdit.Text
    'different action depending on which button was clicked
    Select Case CommandBars.ActionControl.Caption
    Case "Command 1"
    'code for command 1 or call a routine
    Case "Command 2"
    'code for command 2 or call a routine
    Case "Command 3"
    'code for command 3 or call a routine
    End Select
    MsgBox "Do " & CommandBars.ActionControl.Caption & " with value: " & myVal
    Else
    MsgBox "No value entered"
    End If
    Else
    MsgBox "Could not find control"
    End If

    End Sub[/VBA]You can also set other properties on each button ("Paramater" and "Tag") to store values for that action and access tham with the "ActionControl" object
    K :-)

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    oooh! Thanks again Mr. K.... I can't wait to play with this

    Does it matter where I put this code? (normal or class module)

    While building the toolbar, is there a way to specify a different graphic for each button? I have the images saved in a directory -- can I point to those images?

    [Edit] -- For some reason, it's skipping your case statements so no matter what value I put in the textbox, it gives me the messagebox "no value entered". How do I make a value entered stay in the textbox until the user changes it? Also, how do I pass this value on to my macros? It should be a decimal, not text.

    [Edit AGAIN!] -- I wasn't pressing ENTER when entering a new value. I think I'm getting somewhere now...
    Last edited by TrippyTom; 08-04-2006 at 01:35 PM.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  5. #5
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    wow... I actually figured out how to make it work with my code. Thanks Killian.

    I'm still curious to see if I can point the buttons to an image instead of using text.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  6. #6
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    You can put some validation on the value with IsNumeric[VBA] If Not ctrlEdit Is Nothing Then
    If ctrlEdit.Text <> "" Then
    strVal = ctrlEdit.Text
    If IsNumeric(strVal) Then
    'different action depending on which button was clicked
    Select Case CommandBars.ActionControl.Caption
    'etc...

    Else
    MsgBox "Not valid value"
    ctrlEdit.Text = ""
    End If
    'etc...[/VBA]or you can try casting it to the data type you want (with CLng(strVal), CSng(strVal) etc) and trapping any resulting "Type Mismatch" error.

    Regarding the custom icons, have you seen if there are any BuiltIn office icons you can use?
    (link to FaceID tool)
    K :-)

  7. #7
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Thanks for the isnumeric tip.


    Yeah, I have the Excel add-in that shows all the faces, but nothing in there satisfied my needs. I just need a simple arrow pointing up, down, left, right or at any angle (8 different macros).

    [EDIT]: I decided to get rid of the diagonals since they don't always work as expected. That will let me use faceid: 3274-3276 to use with up, down, left and right. Now if I can just find the right syntax to include them.
    Last edited by TrippyTom; 08-07-2006 at 02:07 PM.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  8. #8
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Ok, I figured it out based on the info on this page:
    http://msdn.microsoft.com/library/de...tml/faceid.asp

    Thanks for all your help!
    marking this solved.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  9. #9
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    In case you wanted to see the final result, here's my add-in.
    Office 2010, Windows 7
    goal: to learn the most efficient way

Posting Permissions

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