我正在尝试将活动工作簿中某个范围的内容复制到另一个工作簿,我发现了一段我认为完全符合我需求的vba代码。 Altough,每次我尝试运行它时,都会收到以下错误:运行时错误'438'对象不支持此属性或方法。 我想问题是我在目标工作簿中选择范围的方式,但没有任何工作。 有人可以帮忙吗?
这就是我所拥有的:
Sub Retânguloarredondado1_Click()
Dim InputFile As Workbook
Dim OutputFile As Workbook
Dim Inputpath As String
Dim Outputpath As String '
Dim TP As Worksheet
' Set path for Input & Output
fileInputpath = "C:\Users\Nuno Bonaparte\Desktop\"
Outputpath = "C:\Users\Nuno Bonaparte\Desktop\"
'## Open both workbooks first:
Set InputFile = ActiveWorkbook
Set OutputFile = Workbooks.Open(Outputpath & "file2.xlsm")
Set TP = OutputFile.Worksheets("Folha1")
'Now, copy what you want from InputFile:
InputFile.Sheets("file2").Activate
InputFile.Sheets("file2").Range("A1:A12").Copy
'Now, paste to OutputFile worksheet:
OutputFile.Sheets("Folha1").Activate
TP.Range("A1").PasteSpecialOutputFile.Save
'Close InputFile & OutputFile:
InputFile.Close
OutputFile.Close
End Sub
答案 0 :(得分:0)
查看此代码是否出现相同的错误:
Sub Retânguloarredondado1_Click()
Dim Paths As String
' Set path
Paths = "C:\Users\Nuno Bonaparte\Desktop\"
'## Open both workbooks first:
Workbooks.Open(Paths & "file1.xlsm")
Workbooks.Open(Paths & "file2.xlsm")
'Now, copy what you want from InputFile:
Workbooks("file1.xlsm").Sheets("file2").Range("A1:A12").Copy
'Now, paste to OutputFile worksheet:
Workbooks("file2.xlsm").Worksheets("Folha1").Range("A1").PasteSpecial
Workbooks("file2.xlsm").Save
'Close InputFile & OutputFile without saving
InputFile.Close False
OutputFile.Close False
End Sub