Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture mult. wksheets when SaveAs .csv or .txt 3

Status
Not open for further replies.

tmktech

MIS
Oct 3, 2002
78
US
Hello all.

Need you help on this one. I've got an Excel / VBA app which permits the user to select and create one or more outputs (hardcopy, PDF, excel, .csv, .txt).

After selecting multiple sheets, I use:
(1) the printout method fine for the hardcopy and PDF.
(2) the copy method for excel
(a) with a saveas filetype for .csv, .txt, and .htm

HOWEVER, on the .csv and .txt types, I only get the ACTIVE worksheet (vs. all selected). I can't activate multiple sheets at once (OR CAN I?)

Any suggestions on how to get all selected sheets into the csv and txt files?

Thanks in advance!!

Rob B.???

 
.csv is a plain-text format - Excel wouldn't know how to put multiple sheets into a single csv file. You can easily cycle through the sheets you need:

for each Sh in sheets(array("dick","jane"))
Sh.saveas "Sheet " & Sh.name & ".csv",xlCSV
next Sh


Rob
[flowerface]
 
Rob,

>>>for each Sh in sheets(array("dick","jane"))

I didn't know I could use an array there!
Thanks!
 
Thanks, Rob.

That's a last resort, but I was hping to get them all in one file. Is there a way to append each time?
 
There are several ways you might go about getting it all into one file. One would be to use sequential file access to write the values as a csv file programmatically. Another would be to write each sheet as a separate .csv file temporarily (as above), then use
shell "command /c copy dick.csv+jane.csv dickandjane.csv"
to concatenate them using DOS (an age-old trick :))
Probably the most flexible is to use VBA to put all the relevant values onto one (temporary) worksheet, with appropriate dividers that tell you (when you read it back) where one sheet stops and the next one starts. Then save that combined sheet as a .csv.
Rob
[flowerface]
 
Thanks, Rob. Here's a star. I've used many of your great suggestions to other posts and want to show my appreciation. Thanks to the participation of you and others, this is an incredibly valuable site. There's some VERY giving folks here.

All the best!

TMKTECH
 
Thanks tmktech, for your words of appreciation. Knowing that people care makes me stick around here (that, and learning new things all the time!)
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top