TOM I have put a wrong question

7

71marco71

I'm sorry Tom but I have confuse workbooks and sheet. I repeat my
question
I have a macro that join more workbooks in one.
I would like to write this macro in one WORKBOOK named “report” and
copy to it every month all sheets contained in the others workbooks I
want to join. Than I would like to number the pages.
Someone can help me?
Thank you very much for your help

bkList = Array("Bk1.xls", "Bk2.xls", "Bk3.xls", "Bk4.xls", "Bk5.xls",
"Bk6.xls", "Bk7.xls")
for i = lbound(bkList) to ubound(bklist)
set wkbk = workbooks.Open(blList(i))
if i = lbound(bkList) then
wkbk.Sheets.copy> set wkbk1 = ActiveWorkbook
else
wkbk.Sheets.Copy After:=wkbk1.Sheets(wkbk1.sheets.count)
end if
Next
 
T

Tom Ogilvy

Dim bkList as Variant
Dim wkbk1 as Workbook
Dim wkbk as Workbook
Dim i as long
bkList = Array("Bk1.xls", "Bk2.xls", "Bk3.xls", _
"Bk4.xls", "Bk5.xls", "Bk6.xls", "Bk7.xls")
set wkbk1 = Workbooks("Report.xls")
for i = lbound(bkList) to ubound(bklist)
set wkbk = workbooks.Open(bkList(i))
wkbk.Sheets.Copy After:=wkbk1.Sheets(wkbk1.sheets.count)
wkbk.Close SaveChange:=False
Next

If you want to print out the data with sequentially numbered pages, just set
up the format of each sheet to include a header or footer and put a page
number in the header or footer. Then group the sheets when you print and
the pages will be sequentially numbered.

If you need code to do that, turn on the macro recorder while you set it
manually for one sheet. Then remove any extra formatting recorded which
you don't need (since each command runs as a separate call to the print
driver and they are very slow), and then loop through all the sheets and run
that macro.
 
J

Jonathan Rynd

if i = lbound(bkList) then
wkbk.Sheets.copy> set wkbk1 = ActiveWorkbook
else

Looks like you made a typo here. Could you proofread this and post again?
 
T

Tom Ogilvy

That is called a quote character (>) combined with word wrap. It is two
separate lines of code
if i = lbound(bkList) then
wkbk.Sheets.copy
set wkbk1 = ActiveWorkbook
else
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top