我有一个奇怪的问题,当我将来自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)
"
答案 0 :(得分:0)
要避免从Excel粘贴到记事本或其他应用程序时将引号遗漏,我使用下面的代码将内容放入剪贴板:
Dim obj As New DataObject
obj.SetText NameofYourVariable
obj.PutInClipboard
然后粘贴得很好,没有任何双引号。