You can see Macros for Excel on VBA for copy only values. Hidden rows will be copied too, because here we are not control it, but You can add it in Your code by yuorself, if needed:
Sub CopyOnlyValuesCell()
On Error Resume Next
Dim str As String
Dim arrData() As Variant
Dim arrReturnData() As Variant
Dim rng As Excel.Range
Dim lRows As Long
Dim lCols As Long
Dim i As Long, j As Long
lRows = Selection.Rows.Count
lCols = Selection.Columns.Count
ReDim arrData(1 To lRows, 1 To lCols)
ReDim arrReturnData(1 To lRows, 1 To lCols)
Set rng = Selection
arrData = rng.Value
If Selection.Count = 1 Then
str = ActiveCell.Value
Else
For i = 1 To lRows
For j = 1 To lCols
If j > 1 Then
str = str & Chr(9) & (arrData(i, j))
Else
str = str & arrData(i, j)
End If
Next j
If i > 0 Then str = str & Chr(13) & Chr(10)
Next i
End If
CopyTextToClipboard (str)
Set rng = Nothing
End Sub
CopyTextToClipboard is our function. We can do it so:
Sub CopyTextToClipboard(ByVal inText As String)
Dim objClipboard As Object
Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
objClipboard.SetText inText
objClipboard.PutInClipboard
Set objClipboard = Nothing
End Sub
Function GetTextFromClipboard() As String
Dim objClipboard As Object
Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
objClipboard.GetFromClipboard
GetTextFromClipboard = objClipboard.GetText
Set objClipboard = Nothing
End Function
Комментариев нет:
Отправить комментарий