Change the Border color when adding a TextBox

Omer_K

Board Regular
Joined
Apr 9, 2017
Messages
124
Office Version
  1. 365
Hey all,
I have a VBA code that works fine where I add a textbox with some text,
I would like to know how I add a line to the code that changes the border color of the text box to red
I would appreciate your assistance :)

This is my VBA code:
VBA Code:
With grp(j)


With ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left + ((.Width * 2 + 100) - sTxtW) / 2, .Top - 60, sTxtW, sTxtH)


.Fill.Visible = msoFalse






With .TextFrame2.TextRange.Characters


Text = "Test" & vbCrLf & "No " & sbg "


.ParagraphFormat.Alignment = msoAlignCenter


With .Font


.Fill.Visible = msoTrue


.Fill.ForeColor.ObjectThemeColor = msoThemeColorText1


.NameComplexScript = "Arial"


.Size = 20






End With


End With


With .Line


.Visible = msoTrue


.ForeColor.ObjectThemeColor = msoThemeColorText1


End With


End With


End With


Next


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Have a look at this macro that makes a textbox frame red. I hope that it helps.

VBA Code:
Sub MakeTextBox()
'
    Dim wsTarget As Worksheet
    
    Dim oTextBox As Object
     
    Dim iLeft As Long
    
    Dim iTop As Long
    
    Dim iWidth As Long
    
    Dim iHeight As Long
    
    iLeft = 120
    
    iTop = 30
    
    iWidth = 150
    
    iHeight = 60
    
    Set wsTarget = ThisWorkbook.Worksheets("Sheet1")

    Set oTextBox = wsTarget.Shapes.AddTextbox(msoTextOrientationHorizontal, iLeft, iTop, iWidth, iHeight)
    
    With oTextBox
        
        .TextFrame.Characters.Text = "Test Test Box"
        
        .Name = "TestTextBox"

        With .Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorBackground1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0
            .Transparency = 0
            .Solid
        End With
'
        With .Line
            .Visible = msoTrue
            
'           Lighter red
'           .ForeColor.RGB = RGB(192, 0, 0)
            
'           Darker Red
            .ForeColor.RGB = RGB(164, 0, 0)

            .Transparency = 0
            .Weight = 1
        End With
    
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,433
Messages
6,124,863
Members
449,195
Latest member
MoonDancer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top