VBA/Excel/Access/Word/Word/Document Selection — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:48, 26 мая 2010

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