In Excel - Producing a Solid background and recognizing a CR

Bright01
Bright01 used Ask the Experts™
on
EE Pros,

I have some code that was written for me to bring up a notepad for me to input notes.  Here are my two asks;

1.) How do I put a solid white background on the Note section (it expands to cover the text entered)

and

2.) How do I get it recognize a Carriage Return?  Right now I have to hit Alt. Return to get it to do a normal Carriage Return.

CODE:

option Explicit
Sub ShowTextBox()
Dim shp As Shape
Dim ws As Worksheet
Dim wn As Window
Dim sngHeight As Single, sngLeft As Single, sngTop As Single, sngWidth As Single

Set ws = ActiveSheet
On Error Resume Next
Set shp = ws.Shapes("Notes")
On Error GoTo 0
Set wn = Application.ActiveWindow
sngLeft = wn.Left + ws.Cells(wn.ScrollRow, wn.ScrollColumn).Left + wn.Width * 0.5
sngWidth = 10
sngTop = wn.Top + ws.Cells(wn.ScrollRow, wn.ScrollColumn).Top + wn.Height / 8
sngHeight = 800

ws.Protect Password:="PASSWORD", UserInterFaceOnly:=True, DrawingObjects:=False
'ActiveSheet.Unprotect Password:="PASSWORD"

If shp Is Nothing Then
    Set shp = ws.Shapes.AddTextbox( _
        Orientation:=msoTextOrientationHorizontal, Left:=sngLeft, Top:=sngTop, Width:=sngWidth, Height:=sngHeight)
    shp.Name = "Notes"
Else
    shp.Top = sngTop
    shp.Left = sngLeft
    shp.Visible = msoTrue
End If

shp.TextFrame2.AutoSize = msoAutoSizeShapeToFitText
shp.Select
'Selection.PrintObject = 0

'Selection.PrintObject = msoFalse

End Sub

Sub ResizeTextbox()
On Error Resume Next
ActiveSheet.Shapes("Notes").TextFrame2.AutoSize = msoAutoSizeShapeToFitText
On Error GoTo 0
End Sub

Sub HideTextBox()
On Error Resume Next
ActiveSheet.Shapes("Notes").Visible = msoFalse
ActiveSheet.Protect Password:="jam"
On Error GoTo 0
End Sub

Thank you in advance.

B.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

I have amended your code to get the required output. please see attached example file.

Note:

you can change the shape interior color as follow.

ActiveSheet.Shapes("Notes").Interior.ColorIndex = 2  

the use Carriage Return you should use chr(10) or chr(13) as follow.

ActiveSheet.Shapes.Range(Array("Notes")).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Text to write" & Chr(10) & "Text to write"




Best,
Shape.xlsb

Author

Commented:
Excel amusant,

Where do I put the;

ActiveSheet.Shapes("Notes").Interior.ColorIndex = 2  

Code?

B.

Author

Commented:
It works!  Great..... "much thanks".........

B.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial