exporting multiple sheets to multiple files

c_lansman

New Member
Joined
Jun 11, 2008
Messages
27
I need to create a macro that will allow me to export two sheets at a time from my current workbook to a new workbook and password protect it.

ex.

current workbook

sheet1, ads,dr,hr, ...ect

export:
sheet1, ads then sheet1,dr then sheet1,hr ...ect

each to a new file with name corresponding to the second sheet exported.

ex.

sheet1, ads

filename: ads.xls

and have it password protected.

thanks
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
edit: made a fix

For i = 1 To UBound(sheetArray)
Sheets(sheetArray(i)).Select
Sheets("Sheet1").Select False
ActiveWindow.SelectedSheets.Copy
ActiveWorkbook.SaveAs Filename:= _
sheetArray(i), _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close
Next i
 
Upvote 0
have an add on question to the one above.

I now have it exporting just fine.


How would i go about exporting it to a shared http site?

ex///

ActiveWorkbook.SaveAs Filename:= _
"http://mylocation/" & Format(Now, "mm.dd.yy") & "/" & sheetArray(i), _
FileFormat:=xlNormal, Password:=passArray(i), WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

throws an error, what is wrong with the above code?
 
Upvote 0
edit: sorry for all the posts, the site does not allow you to edit or delete your own posts.

Got the save to http working, now have an even stranger problem.

it starts saving and on the 6th file save it throws a runtime error 1004.

any reason why the first few work and the 6th fails?

I tried resaving each to my documents and they all saved just fine.

thanks
 
Upvote 0
That looks fine.

What about the loop counter for the sheetArray ?
We can not see Lower/Upper bound of sheetArray.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,011
Members
448,935
Latest member
ijat

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