Trin 5 – Eksempler fra den virkelige verden

Slette alle rækker i en tabel, der indeholder en bestemt tekststreng i første kolonne

(Af Bill Coan, Word MVP)

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

Slette alle tomme rækker i en tabel

(Af Dave Rado og Ibby, Word MVP'er)

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

Slette tomme tekstfelter i en præsentation

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

 Trin 1 – Start med makrooptageren

Trin 2 – Læs og forstå koden

Trin 3 – Lær de grundlæggende ting ved programmering

Trin 4 – Del din makro med andre

Trin 5 – Eksempler fra den virkelige verden

Var disse oplysninger nyttige?

Fantastisk! Har du mere feedback?

Hvordan kan vi forbedre det?

Tak for din feedback!

×