[英]Copy and Paste Area are not the Same
I want to copy a specific range on one of my excel sheets to a txt file but when I use the code:我想将我的 excel 工作表之一上的特定范围复制到 txt 文件,但是当我使用代码时:
Sub FromExcelToNpad()
'export activesheet as txt file
Dim myPath As String, myFile As String
myPath = ThisWorkbook.Path & "\"
myFile = "z.txt"
Dim WB As Workbook, newWB As Workbook
Set WB = ThisWorkbook
Application.ScreenUpdating = False
Set newWB = Workbooks.Add
WB.ActiveSheet.UsedRange.Copy newWB.Sheets(1).Range("A4,A10:A22,A28")
With newWB
Application.DisplayAlerts = False
.SaveAs Filename:=myPath & myFile, FileFormat:=xlText
.Close True
Application.DisplayAlerts = True
End With
WB.Save
Application.ScreenUpdating = True
End Sub
keep getting the copy and paste error, it works if I used just range("A4")
but it ends up copying the entire sheet to the txt.不断收到复制和粘贴错误,如果我只使用
range("A4")
它就可以工作,但最终会将整个工作表复制到 txt。
Sub FromExcelToNpad()
'export activesheet as txt file
Dim myPath As String, myFile As String
myPath = ThisWorkbook.Path & "\"
myFile = "z.txt"
Dim WB As Workbook, newWB As Workbook
Set WB = ThisWorkbook
Application.ScreenUpdating = False
Set newWB = Workbooks.Add
WB.ActiveSheet.Range("A4,A10:A22,A28").Copy newWB.Sheets(1).Range("A4")
With newWB
Application.DisplayAlerts = False
.SaveAs Filename:=myPath & myFile, FileFormat:=xlText
.Close True
Application.DisplayAlerts = True
End With
WB.Save
Application.ScreenUpdating = True
End Sub
Thanks @bigben, your comment was enough for me to fix my issue!!!谢谢@bigben,你的评论足以让我解决我的问题!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.