简体   繁体   English

复制和粘贴区域不一样

[英]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.

相关问题 Excel复制粘贴区域不同 - Excel Copy Paste Area not the Same 区域大小不同时无法复制和粘贴 - cannot copy and paste when area size is not the same VBA - 复制区域和粘贴区域的大小不一样错误? - VBA - copy area and paste area aren't the same size error? 我们无法粘贴Excel范围,因为复制区域和粘贴区域的大小不同 - We can't paste Excel ranges because the copy area and paste area aren't the same size 复制粘贴区域大小不一样 VBA 1004 错误 - Copy Paste area is not the same size VBA 1004 Error VBa复制错误“我们无法粘贴,因为复制和粘贴区域的大小不同” - VBa Copy error “We cant paste because the copy and paste area are not the same size” 无法粘贴到过滤后的单元格,错误消息“您无法在此处粘贴此内容,因为复制区域和粘贴区域的大小不同” - Unable to paste in to filtered cells, error message "you can't paste this here because the Copy area and paste area aren't the same size" VBA 您不能在此处粘贴此内容,因为复制和粘贴区域的大小不同 - 错误 - VBA You can't paste this here because the Copy and paste area aren't the same size - error Excel错误1004:复制区域和粘贴区域的大小不同 - Excel error 1004: Copy area and paste area aren't the same size 复制工作表错误:复制区域和粘贴区域的大小不同 - Copying worksheets error: copy area and paste area aren't the same size
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM