复制工作表时,range.value上的VBA错误1004

时间:2021-06-05 23:54:24

Below is the code I am using, but it throws a 1004 error on the range.value line. However it copies successfully the worksheet without formulas (just values). It's just that running this keeps throwing the error 1004.

下面是我正在使用的代码,但它会在range.value行上抛出1004错误。但是,它成功复制了没有公式的工作表(只是值)。这只是运行它不断抛出错误1004。

Sub test1()     
    Dim wbNew As Workbook
    Dim wks As Worksheet
    Set wbNew = Workbooks.Add(xlWBATWorksheet)
    ThisWorkbook.Worksheets.Copy After:=wbNew.Worksheets(1)
    Application.DisplayAlerts = False
    wbNew.Worksheets(1).Delete
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationManual

    For Each wks In wbNew.Worksheets
        wks.UsedRange.Value = wks.UsedRange.Value
    Next wks
    Application.Dialogs(xlDialogSaveAs).Show
End Sub

2 个解决方案

#1


0  

What's the purpose of wks.usedrange.value = wks.usedrange.value? This question is independent of whether the command is permitted by VBA.

wks.usedrange.value = wks.usedrange.value的目的是什么?此问题与VBA是否允许该命令无关。

#2


0  

Can't understand why you trying to do this :

无法理解你为什么要这样做:

For Each wks In wbNew.Worksheets
    wks.UsedRange.Value = wks.UsedRange.Value
Next wks

It's like saying that x = x

这就像说x = x

#1


0  

What's the purpose of wks.usedrange.value = wks.usedrange.value? This question is independent of whether the command is permitted by VBA.

wks.usedrange.value = wks.usedrange.value的目的是什么?此问题与VBA是否允许该命令无关。

#2


0  

Can't understand why you trying to do this :

无法理解你为什么要这样做:

For Each wks In wbNew.Worksheets
    wks.UsedRange.Value = wks.UsedRange.Value
Next wks

It's like saying that x = x

这就像说x = x