Import Sheets to another existing Workbook (VBA)

Asnaghy

New Member
Joined
Sep 1, 2014
Messages
4
Hey there, I'm new here, let's see if u can help me with VBA:

I need to import (copy) all the complete sheets of "WbData" to my "WbMaster".
My "WbMaster" already have 6 sheets, so the copied ones should go after

"WbMaster" has to be the active workbook and "WbData" has to be opened at first and then closed after importing all files

I've been trying but had problems with infinite loops...
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Well, i managed to archieve something but i have two problems now:

1- I could only copy the first sheet, i need an interval or some way to select all sheets
2- When I reactivate the action, the same sheet is copied one more time. So i think i need something like this somewhere(+ with all sheets) :
Code:
wbk1.Sheets("[COLOR=#b22222][U][I]FirstSheet of WbData[/I][/U][/COLOR]").Delete


Code:
Sub Paste_Click()
Dim wbk1 As Workbook, wbk2 As Workbook


fileStr = Application.GetOpenFilename()


Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Add(fileStr)


Application.DisplayAlerts = False


wbk2.Sheets("[COLOR=#b22222][U][I]FirstSheet of WbData[/I][/U][/COLOR]").Copy After:=Workbooks("[COLOR=#b22222][U][I]WbMaster[/I][/U][/COLOR]").Sheets(7)
wbk2.Close


Application.DisplayAlerts = True


End Sub
 
Upvote 0
I fixed the first problem, now I can copy all the sheets I need, however i have a problem deleting all the previous sheets, it can't find any visible sheet.
Can anyone help?

Code:
Sub Paste_Click()
Dim wbk1 As Workbook, wbk2 As Workbook


fileStr = Application.GetOpenFilename()


Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Add(fileStr)


Application.DisplayAlerts = False


wbk2.Sheets(Array("E0", "E1", "E2", "E3", "EC", "SC0", "SC1", "SC2", "SC3", "D1", "D2", "SP1", "SP2", "I1", "I2", "F1", "F2", "N1", "B1", "P1", "G1", "T1")).Select
[COLOR=#b22222]wbk2.Sheets(Array("E0", "E1", "E2", "E3", "EC", "SC0", "SC1", "SC2", "SC3", "D1", "D2", "SP1", "SP2", "I1", "I2", "F1", "F2", "N1", "B1", "P1", "G1", "T1")).Delete[/COLOR]
wbk2.Sheets(Array("E0", "E1", "E2", "E3", "EC", "SC0", "SC1", "SC2", "SC3", "D1", "D2", "SP1", "SP2", "I1", "I2", "F1", "F2", "N1", "B1", "P1", "G1", "T1")).Copy After:=Workbooks("WbMaster").Sheets(7)
wbk2.Close


Application.DisplayAlerts = True


End Sub
 
Last edited:
Upvote 0
Just solved the problem, was pretty stupid...

Code:
Sub Paste_Click()
Dim wbk1 As Workbook, wbk2 As Workbook


fileStr = Application.GetOpenFilename()


Set wbk1 = ActiveWorkbook
Set wbk2 = Workbooks.Add(fileStr)


Application.DisplayAlerts = False


wbk1.Sheets(Array("E0", "E1", "E2", "E3", "EC", "SC0", "SC1", "SC2", "SC3", "D1", "D2", "SP1", "SP2", "I1", "I2", "F1", "F2", "N1", "B1", "P1", "G1", "T1")).Delete
wbk2.Sheets(Array("E0", "E1", "E2", "E3", "EC", "SC0", "SC1", "SC2", "SC3", "D1", "D2", "SP1", "SP2", "I1", "I2", "F1", "F2", "N1", "B1", "P1", "G1", "T1")).Copy After:=Workbooks("WbMaster").Sheets(7)
wbk2.Close


Application.DisplayAlerts = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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