Macro to import data from another spreadsheet

graduate106

Board Regular
Joined
Jul 14, 2011
Messages
91
Hi sorry if this has been asked before but i can not find the info i need.

I basically have a spreadsheet which works out somebody's pension. This spreadsheet is constantly being updated so every time i want to put a client onto the new version of the spreadsheet i need to re-enter all of their details.

I want to create an "Import" button on the master spreadhseet which then opens up a window to browse for a file. I want to be able to then choose the clients saved spreadsheet (which is basically an old proforma) and once i have chosen the file i want it to import all of the client details, ie, copy 100 or so different boxes from the old spreadsheet onto the new one. eg. B5 to B5, C7 to C7 etc.

So, is this actually possible? And if so i would be very grateful for any help.

Cheers
Simon
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi, here is a sample code for you. You can assign this code to the import button on the master worksheet.

Dim OpenFileName As String
Dim wb As Workbook
'Select and Open workbook
OpenFileName = Application.GetOpenFilename("clients saved spreadsheet,*.xls")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)

'Get data EXAMPLE
ThisWorkbook.Sheets(1).Range("B5:C7").Value = wb.Sheets(1).Range("B5:C7").Value

MsgBox ("Done")
 
Upvote 0
Hi, here is a sample code for you. You can assign this code to the import button on the master worksheet.

Dim OpenFileName As String
Dim wb As Workbook
'Select and Open workbook
OpenFileName = Application.GetOpenFilename("clients saved spreadsheet,*.xls")
If OpenFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(OpenFileName)

'Get data EXAMPLE
ThisWorkbook.Sheets(1).Range("B5:C7").Value = wb.Sheets(1).Range("B5:C7").Value

MsgBox ("Done")

That is absolutely superb, thank you Colo.

Can an extra bit of code be entered to close the source file once the import has been done? (currently the old file remains open as well as the new one once the macro has run)
 
Upvote 0
Skip that actually, just added wb.close at the bottom.

My other "problem" is that these old workbooks have links to other workbooks and i get the annoying "do you want to update" message pop up when i import from the file. Can i get it to just choose the "do not update" option to prevent the user from having to click this everytime?
 
Upvote 0
All right, graduate106.
You can ignore that message by adding this one when the target workbook is opened.

UpdateLinks:=0

Code:
Set wb = Workbooks.Open(OpenFileName, UpdateLinks:=0)
 
Upvote 0
All right, graduate106.
You can ignore that message by adding this one when the target workbook is opened.

UpdateLinks:=0

Code:
Set wb = Workbooks.Open(OpenFileName, UpdateLinks:=0)

Colo, that worked fantastic thank you!

One final query then i will leave you alone, is there some similar code i can enter to prevent it from asking me to save the date source file when it is closed?
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top