VBA - 将关闭工作簿中的第一个工作表导入活动工作簿中的命名工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25664089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA - Import the first Sheet from a closed workbook to an named sheet in active workbook
提问by MVAmorim
I'm new to VBA, and I'm looking for a piece of code that allows me to select an Excel file, and import the first sheet from that file to an named sheet (that already exists) in active workbook (the one that runs the macro).
我是 VBA 新手,我正在寻找一段代码,它允许我选择一个 Excel 文件,并将该文件中的第一个工作表导入到活动工作簿中的命名工作表(已存在)(运行宏)。
Thanks
谢谢
回答by Gary's Student
Give this a try:
试试这个:
Sub KopyKat()
Dim sd As Worksheet, rd As Range
Set sd = ThisWorkbook.Sheets("Final Destination")
Set rd = sd.Range("A1")
filespec = Application.GetOpenFilename()
Set wb = Workbooks.Open(Filename:=filespec)
Sheets("Sheet1").Activate
Cells.Copy rd
wb.Close
End Sub