跳到主要内容

如何将数据从封闭的工作簿导入/复制到当前工作簿?

我们很容易从打开的工作表中复制数据并将其粘贴到另一个打开的工作簿中,但是,您是否曾经尝试过将数据从关闭的工作簿导入到打开的工作簿中? 本文,我将讨论如何从封闭的工作簿中导入数据。

使用VBA代码将已关闭工作簿中的数据导入到当前工作簿中

使用 Kutools for Excel 将数据从关闭的工作簿导入当前工作簿


使用VBA代码将已关闭工作簿中的数据导入到当前工作簿中

以下VBA代码可以帮助您从工作簿复制数据而无需将其打开到活动的已打开工作簿中,请执行以下步骤:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口.

VBA代码:将数据从关闭的工作簿导入当前工作簿

Sub ImportDatafromcloseworkbook()
'Updateby Extendoffice
Dim xWb As Workbook
Dim xAddWb As Workbook
Dim xRng1 As Range
Dim xRng2 As Range
Set xWb = Application.ActiveWorkbook
xTitleId = "KutoolsforExcel"
With Application.FileDialog(msoFileDialogOpen)
    .Filters.Clear
    .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
    .AllowMultiSelect = False
    .Show
    If .SelectedItems.Count > 0 Then
        Application.Workbooks.Open .SelectedItems(1)
        Set xAddWb = Application.ActiveWorkbook
        Set xRng1 = Application.InputBox(prompt:="Select source range", Title:=xTitleId, Default:="A1", Type:=8)
        xWb.Activate
        Set xRng2 = Application.InputBox(prompt:="Select destination cell", Title:=xTitleId, Default:="A1", Type:=8)
        xRng1.Copy xRng2
        xRng2.CurrentRegion.EntireColumn.AutoFit
        xAddWb.Close False
    End If
End With
End Sub

3。 然后按 F5 键来运行此代码,然后在 档案开启 窗口中,选择要导入其数据的工作簿,请参见屏幕截图:

来自封闭工作簿1的doc导入数据

4。 然后点击 可选 按钮,和 KutoolsForexcel. 弹出对话框,提醒您选择要导入到其他工作簿的一系列数据,请参见屏幕截图:

来自封闭工作簿2的doc导入数据

5. 然后点击 OK 按钮,在弹出的对话框中,选择要放置数据的单元格,请参见屏幕截图:

来自封闭工作簿3的doc导入数据

6。 并点击 OK,已关闭工作簿中的数据已导入到当前工作簿中。


使用 Kutools for Excel 将数据从关闭的工作簿导入当前工作簿

对于我们的Excel初学者来说,VBA代码可能有些困难,因此,在这里,我将向您推荐一个方便的工具-Kutools for Excel,其 在光标处插入文件 功能,您可以快速轻松地从封闭的工作簿中插入工作表的全部内容。

Kutools for Excel : 带有300多个便捷的Excel加载项,可以在30天内免费试用

安装后 Kutools for Excel,请执行以下操作:

1. 点击 Kutools 加 > 进出口 > 在光标处插入文件,请参见屏幕截图:

来自封闭工作簿5的doc导入数据

2。 在 在光标处插入文件 对话框中,进行以下操作:

(1.)点击 来自封闭工作簿6的doc导入数据按钮选择要放置导入数据的单元格;

(2.)点击 来自封闭工作簿7的doc导入数据按钮选择要导入其数据的工作簿。

请注意: 仅值(无公式):如果选中此选项,则只会导入值,而不会导入公式。

不传输格式:选中此选项会将数据导入到工作表中而不进行格式化。

立即下载并免费试用 Kutools for Excel!

3。 然后点击 OK,如果工作簿中有多个工作表,则 选择一个工作表 对话框将弹出,请指定要导入数据的工作表,请参见屏幕截图:

来自封闭工作簿8的doc导入数据

4。 然后点击 OK 按钮,所选工作表中的数据已导入到当前工作簿中。

单击以了解有关此“在光标处插入文件”功能的更多详细信息。

立即下载和免费试用Excel的Kutools!


演示:使用 Kutools for Excel 将数据从关闭的工作簿导入当前工作簿

Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Missed important thing. Only values need to be imported (not formulas).
This comment was minimized by the moderator on the site
Hi,
I need to import range of data (with keeping formating) from 5 different workbooks (each contain 3 sheets, only one sheet need to be imported) to 5 specified sheets in master workbook (the destination sheet need to have same name all the time, which is different than source sheet name). Every week the source file/sheet name is different. Could you help with this, please?
This comment was minimized by the moderator on the site
Works great, however in the file I open it will only allow me to open from the tab that is was last on. Is there a way to allow me to select the worksheet I want first before I select the cell range?
This comment was minimized by the moderator on the site
Hello, Patrick,When applying the above code, if the prompt box is popped out, you can just click any sheet tab you need, and then select the cell range.Please try it again, thank you!
This comment was minimized by the moderator on the site
it works grate thank you. i am having issue with data copied its formula not the value. how can i copy only value.
This comment was minimized by the moderator on the site
Buen dia! he utilizado su macro y realmente me fue muy util, pero quisiera saber, ¿como puedo agregar una instruccion a la macro para que se peguen solo los valores y no las formulas al libro abierto y también quisiera que al pegar la informacion, agregara una fila adicional para poder seguir pegando datos de otros archivos cerrados...

Esto es porque yo recibo informacion de los candidatos y lo debo de concentrar en un formato maestro.
This comment was minimized by the moderator on the site
Funcionou a primeira vez que tentei.. Agora por algum motivo não esta funcionando mais..Parece que esta copiando os valores apenas. Quando faço alteração de algum dado na planilha, nao esta mudando na outra.. o que devo fazer?
This comment was minimized by the moderator on the site
Thanks for the awesome trick here. I managed to get the coding work with my current project. My question is how can I set ''destination cell'' default to range ''A5'' without popping out InputBox
This comment was minimized by the moderator on the site
Thanks for the above. I'm trying to use VBA but when I reach to step #3: 3. Then press F5 key to run this code, and in the File Open window, select the workbook that you want to import its data I can't "see" the file I need to import the data from! the folder doesn't show that file! What can I do?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations