В VBA вы не должны использовать Ative
.
Поэтому замените все Active
, и вам придется использовать PasteSpecial
, это лучше, чем Paste
Sub test()
Dim uploadfile As Variant
Dim uploader As Workbook
Dim CurrentBook As Workbook
Dim lastRow As Integer
Set CurrentBook = ThisWorkbook
uploadfile = Application.GetOpenFilename()
If uploadfile = "False" Then
Exit Sub
End If
Set uploader = Workbooks.Open(uploadfile)
Application.CutCopyMode = False
uploader.Worksheets(1).Range("A1:J100").Copy
lastRow = CurrentBook.Worksheets(1).Cells(CurrentBook.Worksheets(1).Rows.Count, "A").End(xlUp).Row + 1
Range("A" & lastRow & ":J" & (lastRow + 100)).PasteSpecial xlPasteValues
uploader.Close
End Sub
Этот код работает для меня,
Добро пожаловать:)