Open up multiple workbooks to obtain data with vba

renderman7

New Member
Joined
Oct 27, 2011
Messages
10
Hi All,

I am attempting to get some code working in excel, where it will open up a series of workbooks, copy the data from a sheet out, then paste it onto the main workbook, ideally under the previously pasted data.

I have a list of names for what each workbook is called, so I need some code to go through and open the work book based on value of fname and then fdate, once the copy is done, close the open workbook, without changes and then move onto the next in the list.

Once the list is done, I need a message to appear, saying action complete.

I have this code at the moment, as my starting point, but I can't get it to even recognise the Filename1 part. Any help would be great.

Sub CopyStuff()

Dim wb1 As Workbook, wb2 As Workbook
Dim Filename1 As String

Set wb1 = ActiveWorkbook

fname = Sheets("QA Officer Results").Range("A4").text
fdate = Sheets("QA Officer Results").Range("B2").text

Set Filename1 = fname & " " & fdate
Set wb2 = Workbooks.Open(filename1)

wb2.Sheets(1).Cells.Copy.wb1.Sheets(1).Cells

wb2.Close SaveChanges:=False

Set wb2 = Nothing
Set wb1 = nothing


End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You only Set objects, not strings, the code should be
Code:
Filename1 = fname & " " & fdate
 
Upvote 0

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

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