[英]Copy and Paste Area are not the Same
我想將我的 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
不斷收到復制和粘貼錯誤,如果我只使用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
謝謝@bigben,你的評論足以讓我解決我的問題!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.