Alguns dias atrás eu precisava de algo parecido com o que knezmilos pediu, e eu não encontrei nada para fazer isso. Então, criei uma macro VBA (Word 2016) para fazer exatamente isso. A macro funciona de quatro maneiras diferentes:
- Desloque todas as células para a direita até o final da tabela (Public Sub MoveCellsRight)
- Desloque todas as células para a direita até a primeira célula em branco (Public Sub MoveCellsRightFirstBlankCell)
- Desloque todas as células para a esquerda até o início da tabela (Public Sub MoveCellsLeft)
- Desloque todas as células para a esquerda até a primeira célula em branco (Public Sub MoveCellsLeftFirstBlankCell)
Esta macro NÃO :
- Trabalhe com tabelas dentro de uma célula.
- Trabalhe com células divididas (cada linha deve ter o mesmo número de colunas).
- Preserve o formato da célula. (Espero que alguém melhore essa macro adicionando esse recurso).
Aqui está a macro:
Option Explicit
Dim vmCurrentTableIndex As Integer
Dim vmCurrentTableRowCount As Integer
Dim vmCurrentTableColCount As Integer
Dim vmCurrentCellRow As Integer
Dim vmCurrentCellCol As Integer
Dim vmDirection As String
Enum StopCellMode
FirstLastCell = 0
FirstBlankCell = 1
End Enum
Public Sub MoveCellsRight()
If SetModuleVariables("right") Then
If CheckCurrentCellPosition() Then
MoveCellContent (FirstLastCell)
End If
End If
End Sub
Public Sub MoveCellsLeft()
If SetModuleVariables("left") Then
If CheckCurrentCellPosition() Then
MoveCellContent (FirstLastCell)
End If
End If
End Sub
Public Sub MoveCellsRightFirstBlankCell()
If SetModuleVariables("right") Then
If CheckCurrentCellPosition() Then
MoveCellContent (FirstBlankCell)
End If
End If
End Sub
Public Sub MoveCellsLeftFirstBlankCell()
If SetModuleVariables("left") Then
If CheckCurrentCellPosition() Then
MoveCellContent (FirstBlankCell)
End If
End If
End Sub
Private Function SetModuleVariables(vpDirection As String) As Boolean
Dim vsOK As Boolean
Dim vsMsgBoxValue As Integer
'Check if the [cursor | insertion point] is inside a table.
If ActiveDocument.ActiveWindow.Selection.Information(wdWithInTable) Then
vsOK = True
'Get the index of the current table. / Source: https://wordmvp.com/FAQs/MacrosVBA/GetIndexNoOfPara.htm
vmCurrentTableIndex = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count
vmCurrentTableRowCount = ActiveDocument.Tables(vmCurrentTableIndex).Rows.Count
vmCurrentTableColCount = ActiveDocument.Tables(vmCurrentTableIndex).Columns.Count
vmCurrentCellRow = ActiveDocument.ActiveWindow.Selection.Cells(1).RowIndex
vmCurrentCellCol = ActiveDocument.ActiveWindow.Selection.Cells(1).ColumnIndex
vmDirection = vpDirection
Else
vsMsgBoxValue = MsgBox("This command can be executed only within a table.", vbInformation, "Error")
vsOK = False
End If
SetModuleVariables = vsOK
End Function
Private Function CheckCurrentCellPosition() As Boolean
Dim vsOK As Boolean
Dim vsMsgBoxValue As Integer
vsOK = True
If vmDirection = "right" Then
If vmCurrentCellRow = vmCurrentTableRowCount And vmCurrentCellCol = vmCurrentTableColCount Then
vsMsgBoxValue = MsgBox("This is the last cell. There is no cell to move to the right.", vbCritical, "Error")
vsOK = False
End If
Else
If vmCurrentCellRow = 1 And vmCurrentCellCol = 1 Then
vsMsgBoxValue = MsgBox("This is the first cell. There is no cell to move to the left.", vbCritical, "Error")
vsOK = False
End If
End If
CheckCurrentCellPosition = vsOK
End Function
Private Sub MoveCellContent(vpStopCellMode As StopCellMode)
Dim vsCol As Integer
Dim vsRow As Integer
Dim vsStartRow As Integer
Dim vsStartCol As Integer
Dim vsEndRow As Integer
Dim vsEndCol As Integer
Dim vsStep As Integer
Dim IsStartColSet As Boolean
Dim vsCurrentCellContent As String
Dim vsPreviousCellContent As String
Dim vsLenght As Integer
vsPreviousCellContent = ""
IsStartColSet = False
vsStartRow = vmCurrentCellRow
vsStartCol = vmCurrentCellCol
If vmDirection = "right" Then
vsStep = 1
vsEndRow = vmCurrentTableRowCount
vsEndCol = vmCurrentTableColCount
Else
vsStep = -1
vsEndRow = 1
vsEndCol = 1
End If
For vsRow = vsStartRow To vsEndRow Step vsStep
For vsCol = vsStartCol To vsEndCol Step vsStep
vsLenght = Len(ActiveDocument.Tables(vmCurrentTableIndex).Cell(vsRow, vsCol).Range.Text) - 2
vsCurrentCellContent = Left(ActiveDocument.Tables(vmCurrentTableIndex).Cell(vsRow, vsCol).Range.Text, vsLenght)
ActiveDocument.Tables(vmCurrentTableIndex).Cell(vsRow, vsCol).Range.Text = vsPreviousCellContent
vsPreviousCellContent = vsCurrentCellContent
If vsCurrentCellContent = "" And vpStopCellMode = FirstBlankCell Then
Exit Sub
End If
Next
If IsStartColSet = False Then
If vmDirection = "right" Then
vsStartCol = 1
Else
vsStartCol = vmCurrentTableColCount
End If
IsStartColSet = True
End If
Next
End Sub