Excel 2010 - 当我粘贴复制的单元格时,为什么它在引号中并且缺少换行符



我有一个奇怪的问题,当我将数据从 excel 复制的单元格粘贴到 NotePad++ 时,它会将数据放在引号内并错过单元格中的换行符。

正在从VBA脚本创建复制范围(尽管我尝试手动复制一个单元格),该脚本还将数据添加到单元格中。

这是代码,以防它有帮助:

Sub Ready_For_Infra()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim cell As Range
    Dim i As Long, lastrow As Long, lastcol As Long, g As Long
    Dim str1 As String
    Set ws1 = Worksheets("InfraData")
    Set ws2 = Worksheets("ActionPlan")
    ws1.Cells.Clear
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    With ws2
        lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
        lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        For i = lastrow To 2 Step -1
            str1 = ""
            For Each cell In .Range(.Cells(i, 6), .Cells(i, lastcol))
                g = i - 1
                If cell.Column <> 4 And cell.Column <> 5 And cell.Value <> "" And cell.Value <> "NEW ACTION" Then str1 = str1 & cell.Value & Chr(10) & "(" & cell.Offset(-g, 0).Value & ")" & Chr(10)
            Next cell
            ws1.Range("A" & 2 + lastrow - i).Value = ws2.Cells(i, 1).Value & Chr(10) & Chr(10) & ws2.Cells(i, 2).Value & Chr(10) & Chr(10) & str1
        Next i
    End With
    ws1.Range("A2", "A" & lastrow).Copy
With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With
MsgBox "Done"

End Sub

粘贴的数据应如下所示:

1
Testing1
Another Day of testing
(05/03/2014)

而是看起来像这样:

"1Testing1AnotherDayoftesting(05/03/2014)"

但是,当我将其粘贴到此处时,它似乎包括换行符和空格,但仍包含引号。(见下文)

"1
Testing1
Another Day of testing
(05/03/2014)
"

为了解决从Excel粘贴到记事本或其他内容时省略引号的问题,我使用以下代码将内容放入剪贴板:

Dim obj As New DataObject
obj.SetText NameofYourVariable
obj.PutInClipboard

然后它粘贴得很好,没有任何双引号。

最新更新