Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export each worksheet to csv

Hi. I've been trying to automate exporting each worksheet in a workbook as a
separate CSV file. I've concocted my own macro by using the recorder and
adapting several other macros I came across, but it doesn't work (I have to
admit I'm not really familiar with VBA):

Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As Sheet

ChDir "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In Sheets
ActiveSheet
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\trickster\My
Documents\Voltec\", FileFormat:=xlCSV, CreateBackup:=False & Fname

Sh.Save
Next Sh
Application.StatusBar = "All Sheets Saved."

End Sub

When I run this, I get Compile error:

User-defined type not defined.

Perhaps someone could help me get it working?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export each worksheet to csv


"Trickster" wrote in message
...
Hi. I've been trying to automate exporting each worksheet in a workbook as

a
separate CSV file. I've concocted my own macro by using the recorder and
adapting several other macros I came across, but it doesn't work (I have

to
admit I'm not really familiar with VBA):

Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As Sheet

ChDir "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In Sheets
ActiveSheet
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\trickster\My
Documents\Voltec\", FileFormat:=xlCSV, CreateBackup:=False & Fname

Sh.Save
Next Sh
Application.StatusBar = "All Sheets Saved."

End Sub

When I run this, I get Compile error:

User-defined type not defined.

Perhaps someone could help me get it working?



Well never mind, I found something which pretty much does what I need:

From: Tom Ogilvy
Subject: macro to export each sheet to txt
View: Complete Thread (2 articles)
Original Format
Newsgroups: microsoft.public.excel.programming
Date: 2003-06-19 10:03:19 PST


Dim sh as WorkSheet
for each sh in ThisWorkbook.Worksheets
sh.copy
ActiveWorkbook.SaveAs Thisworkbook.Path & "\" & sh.name & ".csv", _
Fileformat:=xlCsv
ActiveWorkbook.Close SaveChanges:=False
Next



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Export each worksheet to csv

Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As worksheet
Dim sPath as String
Dim fName as String
sPath = "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In workSheets
sh.copy ' creates new workbook
fname = sh.name
ActiveWorkbook.SaveAs Filename:= _
sPath & fname _
& ".csv", FileFormat:=xlCSV, CreateBackup:=False
Activeworkbook.Close SaveChanges:=False

Next Sh
MsgBox "All Sheets Saved."

End Sub

You need to copy each sheet to a new workbook, which this does.

--
Regards,
Tom Ogilvy


Trickster wrote in message
...
Hi. I've been trying to automate exporting each worksheet in a workbook as

a
separate CSV file. I've concocted my own macro by using the recorder and
adapting several other macros I came across, but it doesn't work (I have

to
admit I'm not really familiar with VBA):

Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As Sheet

ChDir "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In Sheets
ActiveSheet
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\trickster\My
Documents\Voltec\", FileFormat:=xlCSV, CreateBackup:=False & Fname

Sh.Save
Next Sh
Application.StatusBar = "All Sheets Saved."

End Sub

When I run this, I get Compile error:

User-defined type not defined.

Perhaps someone could help me get it working?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Export each worksheet to csv

Thanks.

"Tom Ogilvy" wrote in message
...
Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As worksheet
Dim sPath as String
Dim fName as String
sPath = "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In workSheets
sh.copy ' creates new workbook
fname = sh.name
ActiveWorkbook.SaveAs Filename:= _
sPath & fname _
& ".csv", FileFormat:=xlCSV, CreateBackup:=False
Activeworkbook.Close SaveChanges:=False

Next Sh
MsgBox "All Sheets Saved."

End Sub

You need to copy each sheet to a new workbook, which this does.

--
Regards,
Tom Ogilvy


Trickster wrote in message
...
Hi. I've been trying to automate exporting each worksheet in a workbook

as
a
separate CSV file. I've concocted my own macro by using the recorder

and
adapting several other macros I came across, but it doesn't work (I have

to
admit I'm not really familiar with VBA):

Public Sub ExportAsCSV()
'
' ExportAsCSV Macro
'
'
Dim Sh As Sheet

ChDir "C:\Documents and Settings\trickster\My Documents\Voltec\"

For Each Sh In Sheets
ActiveSheet
ActiveSheet.SaveAs Filename:="C:\Documents and Settings\trickster\My
Documents\Voltec\", FileFormat:=xlCSV, CreateBackup:=False & Fname

Sh.Save
Next Sh
Application.StatusBar = "All Sheets Saved."

End Sub

When I run this, I get Compile error:

User-defined type not defined.

Perhaps someone could help me get it working?






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
How can I export data from one worksheet to another? jtroberts Excel Discussion (Misc queries) 2 September 24th 08 09:52 PM
Export Excel WorkSheet Bette Excel Discussion (Misc queries) 0 July 11th 07 03:42 AM
Needed: worksheet export help mainemike Excel Discussion (Misc queries) 1 February 24th 06 02:59 AM
Export Worksheet to Access R. Choate Excel Programming 2 August 10th 03 01:13 AM
Export Worksheet to Access Sigmund[_2_] Excel Programming 2 August 9th 03 10:10 PM


All times are GMT +1. The time now is 05:25 PM.

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"