ชุดข้อมูลตัวอย่างมีข้อมูลยอดขายอุปกรณ์เสริมต่างๆ ในสถานที่ต่างๆ Text Box ด้านล่างแสดงสรุปชุดข้อมูล แสดงยอดขายสูงสุดและต่ำสุด

Text Box คืออะไร?
Text Box เป็นวัตถุรูปสี่เหลี่ยมผืนผ้าที่สามารถจัดเก็บและแสดงข้อความภายในพื้นที่เฉพาะของเวิร์กชีตได้
วิธีเพิ่ม Text Box ใน Excel: 4 วิธี
ชุดข้อมูลมีข้อมูลยอดขายของบริษัท

วิธีที่ 1 - ใช้ตัวเลือก Text Box
- ไปที่แท็บ Insert และเลือก Text Box ใน Text

เคอร์เซอร์จะเปลี่ยนรูปแบบ
- คลิกที่พื้นที่ในเวิร์กชีตเพื่อแทรก Text Box และลากลงไป

- ป้อนข้อความใน Text Box

ใช้คีย์บอร์ด:
คุณสามารถกด Alt, N, X ได้ มันจะสร้าง Text Box บนเวิร์กชีต
วิธีที่ 2 - เพิ่ม Text Box จาก Shapes
- ไปที่ Insert >> Illustrations >> Shapes
- เลือก Text Box ใน Basic Shapes

เคอร์เซอร์จะเปลี่ยนรูปแบบ
- คลิกที่พื้นที่ในเวิร์กชีตเพื่อแทรก Text Box และลากลงไป

- ป้อนข้อความใน Text Box

วิธีที่ 3 – แทรก Text Box จาก ActiveX Controls ใน Excel
เพื่อแทรก ActiveX Control Text Box:
- เปิดใช้งานแท็บ Developer บน Ribbon
- ไปที่ Developer >> Controls >> Insert
- เลือก Text Box (ActiveX Controls) ใน ActiveX Controls

เคอร์เซอร์จะเปลี่ยนรูปแบบ
- คลิกที่พื้นที่ในเวิร์กชีตเพื่อแทรก Text Box และลากลงไป

- วัตถุอยู่ใน Design Mode เพื่อปิด ให้คลิก Developer >> Controls >> Design Mode

- ป้อนข้อความใน Text Box

หมายเหตุ
ใช้ Shift+Enter เพื่อแทรกการขึ้นบรรทัดใหม่ใน ActiveX Control Text Boxes
เพิ่ม Text Box หลายบรรทัดพร้อม Scrollbar
- สร้าง ActiveX Control Text Box ก่อนด้วยวิธีก่อนหน้า
- คลิกขวา Text Box และเลือก Properties

- ในหน้าต่าง Properties เลือก True เป็น MultiLine
- เลือก 1, 2, หรือ 3 สำหรับ ScrollBars ที่นี่ 2 สำหรับ Scrollbar แนวตั้ง

- ป้อนข้อความของคุณ Scrollbar จะแสดงใน Text Box

วิธีที่ 4 – ใช้ VBA เพื่อเพิ่ม Text Box หลายตัวใน Excel

คลิกที่รูปภาพเพื่อดูรายละเอียด
- ไปที่ Developer >> Code >> Visual Basic

- เลือก Insert >> Module

- แทรกโค้ดต่อไปนี้ใน Module
Sub InsertMultipleTextBoxes()
Dim ws As Worksheet
Dim textBox As Shape
Dim i As Integer
Dim numTextBoxes As Integer
Dim textArray() As String
' Set the worksheet where you want to insert the text boxes
Set ws = ThisWorkbook.Sheets("4.1 VBA Multiple Box")
' Replace "4.1 VBA Multiple Box" with your actual sheet name
' Set the number of text boxes you want to insert
numTextBoxes = 3
' Change this to the desired number
' Array of different texts for each text box
textArray = Split("Sioux City has the highest television sales,Stony Brook has the highest mobile sales,Green Bay has the highest monitor sales", ",")
' Loop to insert multiple text boxes
For i = 1 To numTextBoxes
' Insert a text box
Set textBox = ws.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=50 + (i - 1) * 200, Top:=230, Width:=150, Height:=50)
' Set the text inside the text box
textBox.TextFrame.Characters.Text = textArray(i - 1)
textBox.TextEffect.FontSize = 12
textBox.Line.ForeColor.RGB = RGB(0, 0, 255)
Next i
End Sub

คลิกที่รูปภาพเพื่อดูรายละเอียด
- กด F5 เพื่อรันโค้ด

คลิกที่รูปภาพเพื่อดูรายละเอียด
หมายเหตุ
ใช้โค้ดเดียวกันโดยไม่มี Loop เพื่อสร้าง Text Box เดียว:
Sub InsertTextBox()
Dim ws As Worksheet
Dim textBox As Shape
Set ws = ThisWorkbook.Sheets("4. VBA")
' Replace "4. VBA" with your actual sheet name
Set textBox = ws.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=60, Top:=230, Width:=250, Height:=80)
textBox.TextFrame.Characters.Text = "Total Sales by Store:" & vbNewLine & "Green Bay has the highest total sales with $50,960, followed by Sioux City with $41,614." & vbNewLine & "Rock Island has the lowest total sales at $14,628."
textBox.Line.ForeColor.RGB = RGB(0, 0, 255)
End Sub
วิธีจัดรูปแบบ Text Box ใน Excel
1. เปลี่ยนรูปร่างและแก้ไขจุด (Edit Points)
- คลิก Text Box และไปที่ Shape Format
- เลือก Shape Format >> Insert Shapes >> Edit Shape >> Change Shape

คลิกที่รูปภาพเพื่อดูรายละเอียด
Text Box ที่เลือกจะเปลี่ยนรูปร่าง

เปลี่ยน Edit Points:
- คลิกขอบของ Text Box ตัวชี้เมาส์จะแสดงเครื่องหมายบวกแหลม

- เลือก Shape Format >> Insert Shapes >> Edit Shape >> Edit Points

คลิกที่รูปภาพเพื่อดูรายละเอียด
- คลิกและลากจุดขอบเพื่อย้ายขอบและเปลี่ยนรูปร่างด้วยตนเอง

2. เปลี่ยน Shape Styles
- เลือก Text Box และไปที่แท็บ Shape Format
- เลือก Style ใน Shape Styles

คลิกที่รูปภาพเพื่อดูรายละเอียด
- เข้าถึง Quick Styles โดยคลิกลูกศรลง

คลิกที่รูปภาพเพื่อดูรายละเอียด
- คลิก Style

คลิกที่รูปภาพเพื่อดูรายละเอียด
- Text Box จะเปลี่ยน ที่นี่เลือก Subtle Effect- Black, Dark-1

3. เปลี่ยนสีพื้นหลังของ Text Box
- คลิก Text Box และเลือก Shape Format >> Shape Styles >> Shape Fill
- เลือกสี

คลิกที่รูปภาพเพื่อดูรายละเอียด
คุณยังสามารถเปลี่ยนสีพื้นหลังได้โดยเลือก Fill ใน Font ในแท็บ Home
4. ลบขอบ (Border)
คลิก Text Box และเลือก Shape Format >> Shape Styles >> Shape Outline >> No Outline

คลิกที่รูปภาพเพื่อดูรายละเอียด
ขอบจะถูกลบ

5. เปลี่ยนขนาด ฟอนต์ และสีตัวอักษร
- ไปที่ Home >> Font >> Font Color

หมายเหตุ
เลือกข้อความภายใน Text Box หากคุณต้องการเปลี่ยนสีของมัน
- มีตัวเลือกแก้ไขอื่นๆ ใน Font

- เข้าถึง WordArt Styles ที่แตกต่างกันใน Shape Format

คลิกที่รูปภาพเพื่อดูรายละเอียด
6. เปลี่ยนระยะห่างบรรทัดภายใน Text Box
- เลือกข้อความทั้งหมด
- คลิกขวาข้อความและเลือก Paragraph

- ใน Paragraph เลือก Spacing
- เลือกตัวเลือก Line Spacing ที่ต่างกัน
- คลิก OK

ที่นี่ เลือก 6pt

7. หมุน Text Box
- เลือก Text Box และคุณจะเห็นไอคอนหมุนตามเข็มนาฬิกาที่ด้านบนของกล่อง
- คลิกและเลื่อนเมาส์เพื่อหมุน Text Box
สังเกต GIF

8. ปรับขนาด Text Box ให้พอดีกับข้อความ

ปรับขนาด Text Box ให้พอดีอัตโนมัติ:
- เลือก Text Box โดยคลิกขอบของมัน
- กด Ctrl+1 เพื่อเปิดตัวเลือก Format Shape
- เลือก Text Options >> Textbox
- ใน Text Box เช็ค Resize shape to fit text

คลิกที่รูปภาพเพื่อดูรายละเอียด
ความสูงและความกว้างจะปรับให้ตรงกับข้อความ

คลิกที่รูปภาพเพื่อดูรายละเอียด
Resize to Fit และ Wrap:
- เลือก Wrap text in shape
- ความสูงจะปรับ และความกว้างจะคงที่

คลิกที่รูปภาพเพื่อดูรายละเอียด
นี่คือผลลัพธ์

Resize to Fit ด้วย VBA:
- เปิด VBA Editor และแทรกโค้ดต่อไปนี้ใน Module
Sub FitTextBoxToText()
Dim ws As Worksheet
Dim textBox As Shape
' Set the worksheet
Set ws = ThisWorkbook.Sheets("8. Resize to Fit Text")
' Replace "YourSheetName" with your actual sheet name
' Set the name of the text box
Dim textBoxName As String
textBoxName = "TextBox 1"
' Replace with the actual name of your text box
' Check if the text box exists
On Error Resume Next
Set textBox = ws.Shapes(textBoxName)
On Error GoTo 0
If Not textBox Is Nothing Then
' Fit the text box to its content
textBox.TextFrame.AutoSize = True
Else
MsgBox "Text box not found!"
End If
End Sub

คลิกที่รูปภาพเพื่อดูรายละเอียด
- กด F5 เพื่อรันโค้ด มันจะปรับขนาด Text Box

คลิกที่รูปภาพเพื่อดูรายละเอียด
9. จัดเรียง Text Box ใน Excel

จัดเรียง Text Box แนวนอน (Horizontally):
- เลือก Text Box ทั้งหมดโดยค้าง Ctrl และคลิกซ้ายแต่ละตัว

- เลือก Shape Format >> Align Objects >> Align Top

คลิกที่รูปภาพเพื่อดูรายละเอียด
กล่องจะถูกจัดเรียงแนวนอน

จัดเรียง Text Box แนวตั้ง (Vertically):
- เลือก Text Box ทั้งหมด
- เลือก Shape Format >> Align Objects >> Align Left

คลิกที่รูปภาพเพื่อดูรายละเอียด
นี่จะจัดเรียง Text Box แนวตั้ง

คลิกที่รูปภาพเพื่อดูรายละเอียด
10. เปลี่ยนความโปร่งใสของ Text Box

เพื่อเปลี่ยนความโปร่งใสของ Text Box:
- เลือก Text Box โดยคลิกขอบของมัน
- กด Ctrl+1 เพื่อเปิดหน้าต่าง Format Shape
- เลือก Shape Options >> Fill & Line >> Fill
- เปลี่ยนระดับ Transparency ใน Color

คลิกที่รูปภาพเพื่อดูรายละเอียด
11. ติดตั้ง (Anchor) Text Box ใน Excel

- เลือก Text Box โดยคลิกขอบของมัน
- กด Ctrl+1 เพื่อเปิดหน้าต่าง Format Shape
- เลือก Shape Options >> Size & Properties >> Properties
- เช็ค Don't move and size with cells

คลิกที่รูปภาพเพื่อดูรายละเอียด
Lock Text Box:
- ไปที่ Home >> Cells >> Format >> Protect Sheet

คลิกที่รูปภาพเพื่อดูรายละเอียด
- เอาเครื่องหมาย Edit objects ออก ใน Protect Sheet และคลิก OK

Text Box จะไม่ถูกปรับขนาดเมื่อเปลี่ยนขนาดคอลัมน์หรือแถว

คุณต้อง Unprotect Sheet เพื่อแก้ไข Text Box อีกครั้ง
วิธีก๊อปปี้ Text Box ใน Excel
- เลือก Text Box โดยคลิกขอบของมัน

- กด Ctrl+C เพื่อก๊อปปี้ และ Ctrl+V เพื่อวาง

วิธีทำให้ Text Box เชื่อมโยงกับเซลล์ใน Excel
.
- สร้าง Text Box
- คลิกกลางกล่อง แทนที่จะพิมพ์ข้อความที่นี่ ใช้ Formula Bar
- ป้อน "=" ตามด้วยเซลล์ที่ต้องการอ้างอิง ที่นี่ =$C$16 เพื่อเชื่อมโยงกับ C16

- กด Enter ค่าจะแสดงใน Text Box

- ดับเบิลคลิก Text Box และป้อนข้อความของคุณ

อ่านเพิ่มเติม: Get a Text Box Linked to Cell
วิธีสร้าง Dynamic Text Box ใน Excel

.
- เลือกเซลล์เพื่อแทรกสถานที่ และไปที่ Data >> Data Tools >> Data Validation

- ใน Data Validation เลือก Settings
- เลือก List ใน Allow และป้อนช่วงใน Source ที่นี่ Source data คือ B6:B13

คลิกที่รูปภาพเพื่อดูรายละเอียด
- ลูกศรดรอปดาวน์จะแสดงในเซลล์ เลือกค่า

- ป้อนสูตรต่อไปนี้ใน C17
=VLOOKUP(C16,B6:F13,4,TRUE)

- แทรก Text Box เลือกมัน และเชื่อมโยงกับเซลล์โดยป้อน =$C$17 ใน Formula Bar

อ่านเพิ่มเติม: Add a Dynamic Text Box
วิธีสร้าง Floating Text Box ใน Excel
- เปิดหน้าต่าง VBA
- เลือก Insert >> UserForm

- ใน Toolbox เลือก TextBox และลากวาง Text Box ของคุณ

- ตั้ง Multiline เป็น True และเลือก 2 ในตัวเลือก ScrollBars

- สร้าง Module และป้อนโค้ดต่อไปนี้
Sub floating_text_box()
UserForm1.TextBox1.Text = "Monthly sales of accessories in different branches of XYZ company"
UserForm1.Show vbModeless
End Sub

คลิกที่รูปภาพเพื่อดูรายละเอียด
- กด F5 เพื่อรันโค้ด Floating Text Box จะแสดง

- ป้อนข้อความใน Text Box เหมือน ActiveX Text Box

คลิกที่รูปภาพเพื่อดูรายละเอียด
อ่านเพิ่มเติม: Create Floating Text Box
วิธีเพิ่ม Hyperlink ให้ Text Box ใน Excel
- แทรก Text Box

- เพิ่มการจัดรูปแบบให้กล่อง (ตัวเลือก)

- คลิกขวา Text Box และเลือก Link

- เลือกสถานที่สำหรับลิงก์ใน Insert Hyperlink ที่นี่ เลือก Place in This Document ใน Link to: และเลือกชีตที่ตั้งชื่อไว้

- คลิก OK
Text Box จะทำงานเหมือนปุ่ม การคลิกจะพาเราไปที่หน้าแรก

หมายเหตุ
ใช้ Ctrl+Left click เพื่อเลือก Text Box ที่มี Hyperlink การคลิกซ้ายปกติจะพาคุณไปที่ตำแหน่งที่เชื่อมโยง
อ่านเพิ่มเติม: Anchor Text Box in Excel
วิธีใช้ Conditional Formatting กับ Text Box ใน Excel
ใช้ ActiveX Text Boxes:
- สร้าง ActiveX Text Box
- เลือกกล่อง และเปลี่ยนชื่อใน Name Box ที่นี่ "ConditionalTextBox" ( Design Mode ใน Controls ต้อง Active)

- คลิกขวาที่ชื่อชีต และเลือก View Code

- แทรกโค้ดต่อไปนี้ใน Editor
Private Sub ConditionalTextBox_Change()
If ConditionalTextBox.Value < "0" Then
ConditionalTextBox.BackColor = rgbBlack
If ConditionalTextBox.Value < "0" Then
ConditionalTextBox.ForeColor = rgbWhite
If ConditionalTextBox.Value > "0" Then
ConditionalTextBox.BackColor = rgbWhite
If ConditionalTextBox.Value > "0" Then
ConditionalTextBox.ForeColor = rgbBlack
End Sub

คลิกที่รูปภาพเพื่อดูรายละเอียด
- ปิด VBA Editor
สีจะเปลี่ยนเป็นสีขาวหากค่าเป็นบวก และสีดำหากศูนย์หรือลบ

หมายเหตุ
หาก Text Box ว่างหรือมีค่าที่ไม่ใช่ตัวเลข Fill ก็จะกลายเป็นสีดำ
วิธีแปลงเนื้อหา Text Box ให้เป็นเนื้อหาเซลล์ใน Excel

- เปิด VBA Editor และแทรก Module
- ป้อนโค้ดต่อไปนี้
Sub ConvertTextBoxToCell()
Dim Sh_xRg As Range
Dim Sh_xRow As Long
Dim Sh_xCol As Long
Dim Sh_xTxtBox As textBox
Set Sh_xRg = Application.InputBox("Select a cell):", "Convert Text Box to Cell ", _
ActiveWindow.RangeSelection.AddressLocal, , , , , 8)
Sh_xRow = Sh_xRg.Row
Sh_xCol = Sh_xRg.Column
For Each Sh_xTxtBox In ActiveSheet.TextBoxes
Cells(Sh_xRow, Sh_xCol).Value = Sh_xTxtBox.Text
Sh_xRow = Sh_xRow + 1
Next
End Sub

คลิกที่รูปภาพเพื่อดูรายละเอียด
- กด F5 เพื่อรันโค้ด
- กล่องจะเปิดถามอ้างอิงเซลล์ เลือก B6 (เซลล์แรกที่มี Text Box)

- คลิก OK เพื่อลบ Text Boxes

อ่านเพิ่มเติม: Convert Text Box to Cell
วิธีเพิ่ม Text Box ในกราฟ Excel

- ไปที่ Insert >> Text >> Text Box
- คลิกและลากไปที่พื้นที่ Chart Area ที่คุณต้องการเพิ่ม Text Box

- ป้อนข้อความของคุณใน Text Box

วิธีลบ Text Box ใน Excel

- เพื่อลบ Text Box ให้เลือกมันโดยคลิกขอบของมัน

- กด Delete

ทำอย่างไรเมื่อ Text Box ไม่แสดงใน Excel?
- มันสามารถปิด/เปิดได้ กด Ctrl+6

- หากคุณกด Ctrl+6 มันจะไม่มองเห็น

ดาวน์โหลด Practice Workbook
Text Box in Excel: Knowledge Hub
<< Go Back to Learn Excel
รับแบบฝึกหัด Excel ขั้นสูงพร้อมเฉลยฟรี!