步骤 5 - 实际示例

删除表格第一列中包含特定文本字符串的所有行

(作者:Word MVP Bill Coan)

Sub DeleteRows() 

Dim TargetText As String
Dim oRow As Row
If Selection.Information(wdWithInTable) = False Then Exit Sub
 
TargetText = InputBox$("Enter target text:", "Delete Rows")
 
For Each oRow In Selection.Tables(1).Rows
 
If oRow.Cells(1).Range.Text = TargetText & vbCr & Chr(7) Then oRow.Delete

Next oRow
End Sub

删除表格中的所有空行

(作者:Word MVPs Dave Rado 和 Ibby)

Public Sub DeleteEmptyRows()
Dim oTable As Table, oRow As Range, oCell As Cell, Counter As Long, _
NumRows As Long, TextInRow As Boolean

' Specify which table you want to work on.
Set oTable = Selection.Tables(1)

' Set a range variable to the first row's range
Set oRow = oTable.Rows(1).Range
NumRows = oTable.Rows.Count
Application.ScreenUpdating = False

For Counter = 1 To NumRows
StatusBar = "Row " & Counter
TextInRow = False

For Each oCell In oRow.Rows(1).Cells
If Len(oCell.Range.Text) > 2 Then
'end of cell marker is actually 2 characters
TextInRow = True
Exit For
End If
Next oCell

If TextInRow Then
Set oRow = oRow.Next(wdRow)
Else
oRow.Rows(1).Delete
End If

Next Counter

Application.ScreenUpdating = True

End Sub

删除演示文稿中的空文本框

Sub RemoveEmptyTextBoxes()
Dim SlideObj As Slide
Dim ShapeObj As Shape
Dim ShapeIndex As Integer
For Each SlideObj In ActivePresentation.Slides
For ShapeIndex = SlideObj.Shapes.Count To 1 Step -1
Set ShapeObj = SlideObj.Shapes(ShapeIndex)
If ShapeObj.Type = msoTextBox Then
If Trim(ShapeObj.TextFrame.TextRange.Text) = "" Then
ShapeObj.Delete
End If
End If
Next ShapeIndex
Next SlideObj
End Sub

 步骤 1 - 从宏录制器入手

步骤 2 - 阅读和理解代码

步骤 3 - 了解编程基础知识

步骤 4 - 与他人共享宏

步骤 5 - 实际示例

扩展你的技能
了解培训
抢先获得新功能
加入 Office 预览体验计划

此信息是否有帮助?

谢谢您的反馈!

谢谢你的反馈! 可能需要转接到 Office 支持专员。

×