跳到主要內容

如何將數據從封閉的工作簿導入/複製到當前工作簿?

我們很容易從打開的工作表中復制數據並將其粘貼到另一個打開的工作簿中,但是,您是否曾經嘗試過將數據從關閉的工作簿導入到打開的工作簿中? 本文,我將討論如何從封閉的工作簿中導入數據。

使用VBA代碼將已關閉工作簿中的數據導入到當前工作簿中

使用Kutools for Excel將關閉的工作簿中的數據導入到當前工作簿中


使用VBA代碼將已關閉工作簿中的數據導入到當前工作簿中

以下VBA代碼可以幫助您從工作簿複製數據而無需將其打開到活動的已打開工作簿中,請執行以下步驟:

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

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。 然後點擊 已提交 按鈕,和 Kutoolsfor Excel 彈出對話框,提醒您選擇要導入到其他工作簿的一系列數據,請參見屏幕截圖:

來自封閉工作簿2的doc導入數據

5. 然後點擊 OK 按鈕,在彈出的對話框中,選擇要放置數據的單元格,請參見屏幕截圖:

來自封閉工作簿3的doc導入數據

6。 並點擊 OK,已關閉工作簿中的數據已導入到當前工作簿中。


使用Kutools for Excel將關閉的工作簿中的數據導入到當前工作簿中

對於我們的Excel初學者來說,VBA代碼可能有些困難,因此,在這裡,我將向您推荐一個方便的工具-Excel的Kutools,其 在光標處插入文件 功能,您可以快速輕鬆地從封閉的工作簿中插入工作表的全部內容。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用

安裝後 Excel的Kutools,請執行以下操作:

1. 點擊 Kutools 加 > 進出口 > 在光標處插入文件,請參見屏幕截圖:

來自封閉工作簿5的doc導入數據

2。 在 在光標處插入文件 對話框中,進行以下操作:

(1.)點擊 來自封閉工作簿6的doc導入數據按鈕選擇要放置導入數據的單元格;

(2.)點擊 來自封閉工作簿7的doc導入數據按鈕選擇要導入其數據的工作簿。

注意: 僅值(無公式):如果選中此選項,則只會導入值,而不會導入公式。

不傳輸格式:選中此選項會將數據導入到工作表中而不進行格式化。

立即下載並免費試用Excel的Kutools!

3。 然後點擊 OK,如果工作簿中有多個工作表,則 選擇一個工作表 對話框將彈出,請指定要導入數據的工作表,請參見屏幕截圖:

來自封閉工作簿8的doc導入數據

4。 然後點擊 OK 按鈕,所選工作表中的數據已導入到當前工作簿中。

單擊以了解有關此“在光標處插入文件”功能的更多詳細信息。

立即下載和免費試用Excel的Kutools!


演示:使用Kutools for Excel將數據從封閉的工作簿導入當前工作簿

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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