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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

c_lansman

New Member
Joined
Jun 11, 2008
Messages
27
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

c_lansman

New Member
Joined
Jun 11, 2008
Messages
27
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

c_lansman

New Member
Joined
Jun 11, 2008
Messages
27
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

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Doesn't 6th worksheet contain invalid character for the file name ?
 
Upvote 0

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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,191,165
Messages
5,985,040
Members
439,935
Latest member
Monty238

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
Top