Я выполнял один и тот же код на нескольких подпрограммах, но только одна из них, которая точно такая же, выдает мне эту ошибку, и я не знаю, почему: VBA - Run Time Error 1004 'Application Defined или Object DefinedОшибка '
Это код, и я сделал комментарий, где ошибка относится к:
Sub Copy()
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
' copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(14)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)
'the line below is where the error refers to
targetSheet.Range("A1", "CA50000").Value = sourceSheet.Range("A1", "CA50000").Value
' Close customer workbook
customerWorkbook.Close
End Sub