VBA/Excel/Access/Word/Word/Document Selection — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:33, 26 мая 2010
Содержание
- 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.
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
Move Selection left
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
Using a variable named curSel to restore the selection it collapses, unless collapsing the selection leaves the selection at an end-of-row marker
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
wdStartOfRangeColumnNumber returns the number of the column in which the beginning of the selection or range falls.
Sub selectRange()
Selection.Tables(1).Columns(Selection.Information (wdStartOfRangeColumnNumber)).Select
End Sub