rpmitchell
New Member
- Joined
- Jun 22, 2011
- Messages
- 43
I am attempting to copy sheets named "Lockbox" from various closed workbooks (source workbooks) into one Master workbook (destination workbook). I have found a macro that allows the user to select the files that I want to copy from, and supposedly paste the data into the new Master workbook. It then names the new sheet in the Master workbook extract1. The Macro seems to work, because I see the source books opening, but there is no data on the newly created sheet in the destination workbook. I want the macro to copy the entire sheet and into the destination workbook. The macro allows the user to keep selecting workbooks until they cancel, each time creating a new sheet in the destination workbook, naming it extract2, etc. I think the part of the code that's missing is the actual "copy" piece, where it knows what to copy and paste. I am new to VBA. Can someone please advise. Thanks. Here is the code:
Sub ValuesfromClosedWorkbook()
Dim filetoopen As String
Dim wb As Workbook
Dim ws As Worksheet
filetoopen = Application _
.GetOpenFilename("XL Files (*.xlsx), *.xlsx")
On Error Resume Next
Set wb = Workbooks.Open(filetoopen, True, True)
Set ws = ThisWorkbook.Worksheets.Add
With ws
.Cells.Value = wb.Worksheets("Lockbox").Cells.Value
End With
ws.Name = "extract1"
wb.Close False
filetoopen = Application _
.GetOpenFilename("XL Files (*.xls), *.xls")
On Error Resume Next
Set wb = Workbooks.Open(filetoopen, True, True)
Set ws = ThisWorkbook.Worksheets.Add
With ws
.Cells.Value = wb.Worksheets("Lockbox").Cells.Value
End With
ws.Name = "extract2"
Sub ValuesfromClosedWorkbook()
Dim filetoopen As String
Dim wb As Workbook
Dim ws As Worksheet
filetoopen = Application _
.GetOpenFilename("XL Files (*.xlsx), *.xlsx")
On Error Resume Next
Set wb = Workbooks.Open(filetoopen, True, True)
Set ws = ThisWorkbook.Worksheets.Add
With ws
.Cells.Value = wb.Worksheets("Lockbox").Cells.Value
End With
ws.Name = "extract1"
wb.Close False
filetoopen = Application _
.GetOpenFilename("XL Files (*.xls), *.xls")
On Error Resume Next
Set wb = Workbooks.Open(filetoopen, True, True)
Set ws = ThisWorkbook.Worksheets.Add
With ws
.Cells.Value = wb.Worksheets("Lockbox").Cells.Value
End With
ws.Name = "extract2"