楼上的代码处理不够严谨,如果复制多列,多行,当一行中只有某个或某几个单元格有数据时,粘贴时会产生数据错位挤堆现象,更正如下。
Dim v,v1,v2 As String
With CurrentTable
For i As Integer = .LeftCol To .RightCol
v2 = v2 & chr(9) & .Cols(i).Caption
Next
For r As Integer = .TopPosition To .BottomPosition
v1 = ""
For c As Integer = .LeftCol To .RightCol
If .Cols(c).Visible Then
If .Rows(r).IsNull(c) Then
v1 = v1 & chr(9) & .ToString
Else
v1 = v1 & chr(9) & .Rows(r)(c).ToString
End If
End If
Next
v = v & v1.Trim(chr(9)) & chr(13)
Next
End With
ClipBoard.SetText(v2.Trim(chr(9)) & chr(13) & v.Trim(chr(13)).Replace("Foxtable.Table",""))