Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DJ DJ is offline
external usenet poster
 
Posts: 13
Default Odd behavior with SaveAs

I have an Excel 2000 workbook with 6 worksheets and 1 code module
My code is designed to save each of the worksheets as individual CSV files

After adding a menu item and linking it to my VBA code, the code works a
expected save for one thing; it is saving/renaming the main Excel workboo
as a CSV file with the same name as the last worksheet name, which is not desireable.

Thinking the loop version was somehow including the workbook name, I hardcoded
the worksheet names in my code, but it made no difference

Here's the code
' Loop version
For Each wsTemp In Worksheet
wsTemp.SaveAs Filename:=wsTemp.Name, FileFormat:=xlCSVWindow
Nex

' Brute-force version
Worksheets("Customer").SaveAs Filename:="Customer", FileFormat:=xlCSVWindow
Worksheets("Worksite").SaveAs Filename:="Worksite", FileFormat:=xlCSVWindow
Worksheets("Order").SaveAs Filename:="Order", FileFormat:=xlCSVWindow
Worksheets("Assignment").SaveAs Filename:="Assignment", FileFormat:=xlCSVWindow
Worksheets("Employee").SaveAs Filename:="Employee", FileFormat:=xlCSVWindow
Worksheets("Invoice Detail").SaveAs Filename:="Invoice Detail", FileFormat:=xlCSVWindow

Any help is greatly appreciated

Cheers
d

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Odd behavior with SaveAs

Is your problem due to the fact that after doing a SaveAs, the
activeworkbook assumes that name. So at the end, the activeworkbook is
Employee.csv?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dj" wrote in message
...
I have an Excel 2000 workbook with 6 worksheets and 1 code module.
My code is designed to save each of the worksheets as individual CSV

files.

After adding a menu item and linking it to my VBA code, the code works as
expected save for one thing; it is saving/renaming the main Excel workbook
as a CSV file with the same name as the last worksheet name, which is not

desireable.

Thinking the loop version was somehow including the workbook name, I

hardcoded
the worksheet names in my code, but it made no difference.

Here's the code:
' Loop version:
For Each wsTemp In Worksheets
wsTemp.SaveAs Filename:=wsTemp.Name, FileFormat:=xlCSVWindows
Next


' Brute-force version:
Worksheets("Customer").SaveAs Filename:="Customer",

FileFormat:=xlCSVWindows
Worksheets("Worksite").SaveAs Filename:="Worksite",

FileFormat:=xlCSVWindows
Worksheets("Order").SaveAs Filename:="Order", FileFormat:=xlCSVWindows
Worksheets("Assignment").SaveAs Filename:="Assignment",

FileFormat:=xlCSVWindows
Worksheets("Employee").SaveAs Filename:="Employee",

FileFormat:=xlCSVWindows
Worksheets("Invoice Detail").SaveAs Filename:="Invoice Detail",

FileFormat:=xlCSVWindows


Any help is greatly appreciated!

Cheers,
dj



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Odd behavior with SaveAs

Dim sh as Worksheet
for each sh in Activeworkbook.worksheets
sh.copy ' puts copy of sh in a new workbook which is now
' the activeworkbook
activeworkbook.Saveas Filename:=ActiveSheet.Name, FileFormat:=xlCSVWindows
' close without prompt - it has already been saved
activeworkbook.Close Savechanges:=False
Next

--
Regards,
Tom Ogilvy

"dj" wrote in message
...
I have an Excel 2000 workbook with 6 worksheets and 1 code module.
My code is designed to save each of the worksheets as individual CSV

files.

After adding a menu item and linking it to my VBA code, the code works as
expected save for one thing; it is saving/renaming the main Excel workbook
as a CSV file with the same name as the last worksheet name, which is not

desireable.

Thinking the loop version was somehow including the workbook name, I

hardcoded
the worksheet names in my code, but it made no difference.

Here's the code:
' Loop version:
For Each wsTemp In Worksheets
wsTemp.SaveAs Filename:=wsTemp.Name, FileFormat:=xlCSVWindows
Next


' Brute-force version:
Worksheets("Customer").SaveAs Filename:="Customer",

FileFormat:=xlCSVWindows
Worksheets("Worksite").SaveAs Filename:="Worksite",

FileFormat:=xlCSVWindows
Worksheets("Order").SaveAs Filename:="Order", FileFormat:=xlCSVWindows
Worksheets("Assignment").SaveAs Filename:="Assignment",

FileFormat:=xlCSVWindows
Worksheets("Employee").SaveAs Filename:="Employee",

FileFormat:=xlCSVWindows
Worksheets("Invoice Detail").SaveAs Filename:="Invoice Detail",

FileFormat:=xlCSVWindows


Any help is greatly appreciated!

Cheers,
dj



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SaveAs SarahN Excel Discussion (Misc queries) 3 May 14th 10 04:26 AM
VBA SaveAs Value charlie Excel Discussion (Misc queries) 4 August 27th 07 11:33 PM
SaveAs Stan Halls Excel Worksheet Functions 5 November 28th 06 07:51 PM
Help with SaveAs Glen Mettler[_2_] Excel Programming 1 January 29th 04 05:32 PM
SaveAs... Chris Gorham[_3_] Excel Programming 2 December 27th 03 04:50 PM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"