gpt4 book ai didi

excel - VBA,ThisWorkbook 对象不支持属性或方法

转载 作者:行者123 更新时间:2023-12-04 21:46:26 35 4
gpt4 key购买 nike

我正在尝试从一个工作簿复制到另一个工作簿。我首先打开工作簿 B 并尝试复制到工作簿 A。但是我收到错误 Object doesnt support this property or method在线ThisWorkbook.Sheets("BusinessDetails").Range("C4").Paste不应该 ThisWorkbook引用运行代码的工作簿和模块?我在这里想念什么?
谢谢。

  Sub Update()

Dim FilePath As String
Dim fname As Variant
Dim myPath As String
Dim Source As Workbook


Application.DisplayAlerts = False


LastRowclear = WorksheetFunction.Max(Sheets("BusinessDetails").Cells(Rows.Count, "AF").End(xlUp).Row)
Worksheets("BusinessDetails").Range("C4:AF" & LastRowclear).Clear
myPath = "sample path"
fname = Dir(myPath & "Business_Level_Report*")

Set Source = Workbooks.Open(myPath & fname)
With Source
.Activate
LastRow = WorksheetFunction.Max(Sheets("BusinessDetails").Cells(Rows.Count, "AE").End(xlUp).Row)
Source.Sheets(1).Range("B4:AE" & LastRow).Copy
End With

ThisWorkbook.Sheets("BusinessDetails").Range("C4").Paste

Workbooks(fname).Close savechanges:=False

End Sub

最佳答案

没有Range.Paste方法。问题与ThisWorkbook无关.
我会使用 Destination Range.Copy的参数:

Source.Sheets(1).Range("B4:AE" & LastRow).Copy _
Destination:=ThisWorkbook.Sheets("BusinessDetails").Range("C4")
虽然你也可以使用 Range.PasteSpecialxlPasteAll .

关于excel - VBA,ThisWorkbook 对象不支持属性或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64103589/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com