Skip to content

Commit 13de962

Browse files
authored
Add files via upload
1 parent 4c75b9c commit 13de962

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

VBA Script/文本框转文字.vba

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Sub ConvertTextBoxesToText()
2+
Dim shp As Shape
3+
Dim rng As Range
4+
Dim textToInsert As String
5+
6+
'确保有内容被选中
7+
If Selection.Type <> wdSelectionShape Then
8+
MsgBox "请先选择文本框。"
9+
Exit Sub
10+
End If
11+
12+
'遍历选中的文本框
13+
For Each shp In Selection.ShapeRange
14+
If shp.Type = msoTextBox Then
15+
'提取文本框中的文本
16+
textToInsert = shp.TextFrame.TextRange.Text
17+
'删除文本框
18+
shp.Delete
19+
'将文本插入到文档中
20+
If rng Is Nothing Then
21+
Set rng = ActiveDocument.Range(Selection.Start, Selection.Start)
22+
Else
23+
Set rng = ActiveDocument.Range(rng.End, rng.End)
24+
End If
25+
rng.InsertAfter textToInsert
26+
rng.Collapse wdCollapseEnd
27+
End If
28+
Next shp
29+
End Sub

0 commit comments

Comments
 (0)