PDA

View Full Version : VBA Importing a sheet from a closed excel workbook



Nirmall
02-11-2016, 09:24 AM
I have created a master workbook, where a sheet has formulas and it is from A1:Z70.

Now i have many workbooks, where each workbook has one sheet with data in it.The data in those sheets are within the range mentioned above.
Now say there are 30 such workbooks in a folder, and when i open the the master workbook and enter the the file name of one of the 30 excel workbooks, it should import data from that particular workbook, without opening it , by jus running a macro.
How do i do this, any help would be appreciated

rcastilho91
02-12-2016, 01:51 PM
The coding could be more or less like this:



Sub ImportData()


Dim wbBook As ThisWorkbook
Dim Rng As Range
Dim wbImportMe As Workbook

Set wbImportMe = Workbooks.Open("C:\Desktop\SourceExcel.xls") '<---- You can also insert the full path in a cell and just reference it here

Application.ScreenUpdating = False

Set Rng = wbBook.Sheets("Sheet1").Range("A1")

Range(Rng, Z70).Select
Selection.Copy

WbBook.Sheets("Sheet1").Range("A1").Select
Selection.Paste

Application.ScreenUpdating = True

End Sub



Hope that helps.

Nirmall
02-13-2016, 02:36 AM
Hi Rcastilho91,

thanks for your reply will check n revert

snb
02-13-2016, 11:29 AM
Without opening the workbook


Set wbImportMe = Workbooks.Open("C:\Desktop\SourceExcel.xls")

I doubt the accordance of the suggestion to the restraint.