gpt4 book ai didi

vba - 通过Excel VBA打开工作簿并复制内容

转载 作者:行者123 更新时间:2023-12-03 07:59:08 25 4
gpt4 key购买 nike

我想打开一个特定文件并从该文件复制单元格并粘贴到 Activity 的工作簿中,但出现错误“438”:对象不支持此属性或方法。

这是我的代码:

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

最佳答案

试试下面的代码

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

关于vba - 通过Excel VBA打开工作簿并复制内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36454384/

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