Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

need a macro or code to cause an action in the workbook

Latest post Wed, Apr 15 2009 5:36 PM by Rollins. 7 replies.
  • Fri, Mar 20 2009 8:42 PM

    • Rollins
    • Top 150 Contributor
    • Joined on Sat, Mar 21 2009
    • Posts 5
    • Points 57

    need a macro or code to cause an action in the workbook

    What I'm looking to do is create a button. When you click this button you activate (Border option) Standard line/automatic color/

    My goal is to have 3 buttons:

    1:  standard line/ automatic color

    2:  dotted line/ red color

    3; erase border

     

    I want to be able to click any button and be ready to do this option anywhere on the sheet.

    Thanks for any help.

    Rollins

    • Post Points: 21
  • Sat, Mar 21 2009 3:08 AM In reply to

    Re: need a macro or code to cause an action in the workbook

    Hi Rollins, this code does the applied changes on the current selection. As you can see you can use the borders collection or the borderaround method, either does the trick

    Private Sub CmdClearBorder_Click()
        With Selection
            .Borders(xlDiagonalDown).LineStyle = xlNone
            .Borders(xlDiagonalUp).LineStyle = xlNone
            .Borders(xlEdgeLeft).LineStyle = xlNone
            .Borders(xlEdgeTop).LineStyle = xlNone
            .Borders(xlEdgeBottom).LineStyle = xlNone
            .Borders(xlEdgeRight).LineStyle = xlNone
            .Borders(xlInsideVertical).LineStyle = xlNone
            .Borders(xlInsideHorizontal).LineStyle = xlNone
        End With
    End Sub

    Private Sub CmdRedBorder_Click()
        With Selection
            .BorderAround LineStyle:=xlDash, Weight:=1, ColorIndex:=3
        End With
    End Sub

    Private Sub CmdStandardBorder_Click()
        With Selection
            .BorderAround LineStyle:=xlContinuous, Weight:=2, ColorIndex:=1
        End With
    End Sub

    • Post Points: 21
  • Sat, Mar 21 2009 3:20 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 543
    • Points 9,287
    • MVP

    Re: need a macro or code to cause an action in the workbook

    Adding to Warren's code (Hi Warren), this is a situation when the macro recorder is more than adequate as it operates generally on the selection you have made, so, this recorded this morning.

    Sub PlainBorder()
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
    End Sub

    Sub RedDottedBorder()
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlDot
            .Color = -16776961
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlDot
            .Color = -16776961
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlDot
            .Color = -16776961
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlDot
            .Color = -16776961
        End With
    End Sub

    Sub NoBorder()
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
    End Sub

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    Filed under: ,
    • Post Points: 21
  • Sat, Mar 21 2009 4:51 AM In reply to

    • Rollins
    • Top 150 Contributor
    • Joined on Sat, Mar 21 2009
    • Posts 5
    • Points 57

    Re: need a macro or code to cause an action in the workbook

    Hey guys thanks alot and I will find a use for this; however, what I'm looking to do is activate the action to allow me to draw these line.

    I'll try to explain this in code form :)  follow my actions in excel

    Sub

     Click the dropdown for borders

     Click Draw border

    ' needs to be solid black line

    End Sub

    So no border is drawn I am ready to draw and I can draw anywhere for as long as I want till I stop the function or change to the Red.

     

    Thanks again guys for the fast response

     

    • Post Points: 21
  • Sun, Mar 22 2009 4:29 AM In reply to

    • Nick Hodge
    • Top 10 Contributor
    • Joined on Sun, Dec 23 2007
    • Southampton
    • Posts 543
    • Points 9,287
    • MVP

    Re: need a macro or code to cause an action in the workbook

    Rollins

    I'm not sure you can do what you want from VBA. If I understand you, by pressing the button on the sheet you want to be able to enter 'draw borders' mode and then press the another button and you are in draw borders mode, but in red colour?

    I think this is something like entering edit mode that cannot be done in excel, except perhaps through a 'SendKeys' operation.

    If you are in versions before 2007 however, you could, of course, create a command bar and have that undocked near your work, if this is what you seek?

    Anyone else find a method that allows Excel to be placed in that mode? A sort of CutCopyMode equivalent? DrawBordersMode?

    Regards
    Nick Hodge
    Microsoft MVP, Excel
    Southampton, UK

    • Post Points: 21
  • Sun, Mar 22 2009 12:07 PM In reply to

    • Rollins
    • Top 150 Contributor
    • Joined on Sat, Mar 21 2009
    • Posts 5
    • Points 57

    Re: need a macro or code to cause an action in the workbook

    I am in version 2007.  For what I'm doing, I need to be able to draw the boarder anywhere on the sheet. And be able to change to the different color and style. right know as you know I have to manualy change that which is very time consuming. 

    If you think of any ideas or avenues I could use please let me know.

    Thanks

    • Post Points: 5
  • Sun, Mar 22 2009 5:06 PM In reply to

    • Rollins
    • Top 150 Contributor
    • Joined on Sat, Mar 21 2009
    • Posts 5
    • Points 57

    Re: need a macro or code to cause an action in the workbook

    I spoke with a friend today whom I found out has done alot with excel. He says scripting. It sounds like I'll have to do some scripting to make this work the way I want it to.

    • Post Points: 5
  • Wed, Apr 15 2009 5:36 PM In reply to

    • Rollins
    • Top 150 Contributor
    • Joined on Sat, Mar 21 2009
    • Posts 5
    • Points 57

    Re: need a macro or code to cause an action in the workbook

    I'd like to revisit this Thread. Let me recap. I have designed A new Ribbon in my workbook. This Ribbon will have various buttons. For starters I have 3.

    Button                 Action                                                                                                                            effect

    Button     -   on click will act as if you clicked "DrawBoarder" then"BoarderStyle" then "BoarderColor"       -     Sheet will be in Draw Boarder mode

     

    Button 1 - thin solid black line

    Button 2 - thin dotted red line

    Button 3 - thin dotted black line

     

    I will be greatful for any help

    Thank you

    Rollins

    • Post Points: 5
Page 1 of 1 (8 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.