VBA/Excel/Access/Word/Word/Document Selection
Содержание
- 1 checks the number of rows and columns in the selection.
- 2 Move Selection left
- 3 Using a variable named curSel to restore the selection it collapses, unless collapsing the selection leaves the selection at an end-of-row marker
- 4 wdStartOfRangeColumnNumber returns the number of the column in which the beginning of the selection or range falls.
checks the number of rows and columns in the selection.
<source lang="vb">
Sub num()
With Selection If .Columns.Count > 1 And .Rows.Count > 1 Then MsgBox "Please select cells in only one row " _ & "or only one column." End Else If .Cells.Count > 1 Then If .Columns.Count > 1 Then .Cells.Delete ShiftCells:=wdDeleteCellsShiftUp Else .Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft End If Else .Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft End If End If End With
End Sub
</source>
Move Selection left
<source lang="vb">
Sub select()
Dim curSel With Documents("yourDocument.doc") If Selection.Information(wdAtEndOfRowMarker) = True Then Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdMove Else If curSel <> "" Then curSel.Select Set curSel = Nothing End If End With
End Sub
</source>
Using a variable named curSel to restore the selection it collapses, unless collapsing the selection leaves the selection at an end-of-row marker
<source lang="vb">
Sub select()
Dim curSel With Documents("yourDocument.doc") If Selection.Type <> wdSelectionIP Then Set curSel = Selection.Range Selection.Collapse Direction:=wdCollapseStart End If End With
End Sub
</source>
wdStartOfRangeColumnNumber returns the number of the column in which the beginning of the selection or range falls.
<source lang="vb">
Sub selectRange()
Selection.Tables(1).Columns(Selection.Information (wdStartOfRangeColumnNumber)).Select
End Sub
</source>