Excel is a professional document used to edit different data information in most cases. But sometimes, people need to insert some text also to explain, comment, remark or something else to help people understand the data information more clearly. To insert a checkbox in Excel, execute these steps: On the Developer tab, in the Controls group, click Insert, and select Check Box under Form Controls. Click in the cell where you want to insert the first checkbox (B2 in this example). Thus, insert textbox becomes necessary. In order to realize this task smoothly, I would like to use a.NET component to help me insert textbox in excel with C#,VB.NET. Spire.XLS uses four steps to finish this task. So it is a good choice to in the system. How to insert textbox in excel with C#,VB.NET Before we start, please create a project in Visual Studio and set your target Framework to be.NET Framework 4. Then, add Spire.XLS DLL as the reference. When you add using Spire.XLS at the top of the method, please make sure that you also add using Spire.Xls.Core. Procedure Step1. Create a workbook and initialize worksheet. Inset Textbox with C# Code: Workbook workbook = new Workbook(); workbook.CreateEmptySheets(1); Worksheet sheet = workbook.Worksheets[0]; Inset Textbox with VB.NET Code: Dim workbook As New Workbook() workbook.CreateEmptySheets(1) Dim sheet As Worksheet = workbook.Worksheets(0). Set texbox format I set the text rotation to be left to right and set the text alignment. There are two types of alignment: vertical and horizontal. In this method, I set both types as center. Inset Textbox with C# Code: textbox.TextRotation = TextRotationType.LeftToRight; textbox.HAlignment = CommentHAlignType.Center; textbox.VAlignment = CommentVAlignType.Center; textbox.Text = 'Insert TextBox in Workbook'; Inset Textbox with VB.NET Code: textbox.TextRotation = TextRotationType.LeftToRight textbox.HAlignment = CommentHAlignType.Center textbox.VAlignment = CommentVAlignType.Center textbox.Text = 'Insert TextBox in Workbook'. Create an ActiveX Text Box on the Worksheet In an Excel worksheet, you can add text boxes from the ActiveX Controls toolbox on the Ribbon's Developer tab. The text box can be linked to a worksheet cell. To manually create the Text Box on the worksheet, follow these steps: • On the Excel Ribbon, click the Developer tab • Click Insert, then click the Text Box control tool • On the worksheet, draw a rectangle with the Text Box tool, to create the Text Box. • With the Text Box selected on the worksheet, click the Properties command on the Ribbon's Developer tab. • In the Properties window, set the properties that you want for the text box, such as Linked Cell. • Close the Properties window. ![]() • On the Ribbon's Developer tab, click the Design Mode setting, to turn it off. • In the Text Box, enter text, and it will appear in the linked cell. Add ActiveX Text Box With VBA Instead of manually adding an ActiveX Text Box to the worksheet, you can add one with programming. In the following macro, a text box is added on sheet 2, and formatted, and linked to cell A2 on the worksheet. Storm hawks sky race game. Sub AddTextBox() Dim ws As Worksheet Dim oTB As Object Set ws = Worksheets('Sheet2') Set oTB = ws.OLEObjects.Add(ClassType:='Forms.TextBox.1') With oTB.Name = 'MyTB'.LinkedCell = '$A$2'.Left = ws.Range('B2').Left.Top = ws.Range('B2').Left.Width = ws.Range('B2').Width.Height = ws.Range('B2').Height.Object.BackColor = RGB(204, 204, 255).Object.ForeColor = RGB(0, 0, 255).Object.Text = 'Hello' End With End Sub More Tutorials Don't Miss Our Excel Tips Don't miss my latest Excel tips and videos! Click OK, to get my weekly newsletter with Excel tips, and links to other Excel news and resources.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |