我想打开一个特定文件并从该文件中复制单元格并粘贴到活动工作簿中,但是我收到错误&#39; 438&#39;:对象不支持此属性或方法。< / p>
这是我的代码:
Sub open_file()
Dim open_book As Variant
com_name = InputBox("Enter Company Ticker", "Enter Company Ticker")
If (IsEmpty(com_name)) Then
msg = MsgBox("Please, enter company ticker", vbCritical)
Else
open_book = Workbooks.Open("E:\Mutual Fund\data\nifty 50\" & com_name & ".xlsx")
Windows(com_name & ".xlsx").Activate
Range("A:A,H:H").Select
Selction.Copy
Windows("try.xlsm").Activate
Range("A1").Select
Selection.Paste
End If
End Sub
答案 0 :(得分:0)
尝试以下代码
Sub open_file()
Dim open_book As Variant
com_name = InputBox("Enter Company Ticker", "Enter Company Ticker")
If (IsEmpty(com_name)) Then
msg = MsgBox("Please, enter company ticker", vbCritical)
Else
Set open_book = Workbooks.Open("E:\Mutual Fund\data\nifty 50\" & com_name & ".xlsx")
Range("A:H").Copy Windows("try.xlsm").ActiveSheet.Range("A1")
End If
End Sub
答案 1 :(得分:0)
您在&#34;上有错字错误SEL的ë强> ction.Copy&#34;
您还应该定义范围来自哪个工作表。如果您使用与您希望应用操作不同的活动页面调用宏,则无法正常工作。 做这样的事情:
open_book.Sheets("My_Sheet").Range("A:A,H:H").Select