E
elle0612
Hi
The following macro works ok if the user selects the table for cutting out
first, which he is supposed to, or, clicks either before or after the table
(because then there is a message box which asks the user to select the table
first).
However, if the user clicks inside the table to be cut, and then presses the
assigned macro button on the toolbar, a debug error message is generated (see
below). Can anyone help me with this workaround, how can I get the message
box to appear in this situation, asking the user to select the table first?
Here's the code,
Sub pastetable()
If Selection.Information(wdWithInTable) Then
Selection.Cut
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.TypeText Text:="this"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="is"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="the"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="example"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="This"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=4
Selection.TypeText Text:="is"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="example"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="of"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="macro"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="working"
Else
MsgBox "Please select a table."
End If
This is the error message I am getting,
"The method or property is not available because the object is empty".
Thanks
The following macro works ok if the user selects the table for cutting out
first, which he is supposed to, or, clicks either before or after the table
(because then there is a message box which asks the user to select the table
first).
However, if the user clicks inside the table to be cut, and then presses the
assigned macro button on the toolbar, a debug error message is generated (see
below). Can anyone help me with this workaround, how can I get the message
box to appear in this situation, asking the user to select the table first?
Here's the code,
Sub pastetable()
If Selection.Information(wdWithInTable) Then
Selection.Cut
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.TypeText Text:="this"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="is"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="the"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="example"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="This"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=4
Selection.TypeText Text:="is"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="example"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="of"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="macro"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="working"
Else
MsgBox "Please select a table."
End If
This is the error message I am getting,
"The method or property is not available because the object is empty".
Thanks