LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Location: Maine, USA
Posts: 8
Send a message via Yahoo to mainemike
Default Needed: worksheet export help

I have a worksheet with four tabs of which three are really needed. I need to have these three worksheets exported to CSV. I was told on here that since my cell lengths are over 255 characters, I will first need to copy the data. This is the order I want all this to be done..

1) User closes the worksheet {Private Sub Workbook_BeforeClose(Cancel As Boolean)}

2) Each individual worksheet is then:
a) check to see if the final exported .csv is already open
1. if so, close it
b) copy worksheet
c) the copy is then saved as tab name.csv without prompting the user

3) Save the original worksheet

On the web, I saw something about having to do something special about copying cells over 255 characters in length...

Set wsSource = ActiveSheet
ActiveSheet.Copy After:=Sheets(Sheets.Count)
Set wsNew = ActiveSheet
'--fixup for cell lengths greater than 255
wsSource.UsedRange.Copy
wsNew.Range("A1").PasteSpecial
Cells.Calculate
'-- following code from MS KB 213548 --
'Clear out the clipboard and select cell A1.
Application.CutCopyMode = False
Range("A1").Select

Do I really need to do this? Up to this point, all the code I've been writing will only export only the ActiveSheet, but will do it four times and all with the same name.

This is the code I currently have (that doesn't function properly). Don't put too much heart into it since I've done alot of fiddling:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim wks As Worksheet
Dim newWks As Worksheet
Dim MyPath As String
Dim FName As String
Dim wksToCopy As Worksheet

Me.Saved = False
MyPath = ActiveWorkbook.Path

Application.DisplayAlerts = False

For Each wks In ActiveWorkbook.Worksheets

FName = wks.Name & ".csv"

' If WorkbookOpen(FName) Then
' Workbooks(FName).Close savechanges:=False
' End If

Set wksToCopy = Worksheets(wks)
wksToCopy.Copy 'copies to a new workbook
Set newWks = ActiveSheet
wksToCopy.Cells.Copy Destination:=newWks.Range("a1")

Next wks

Application.DisplayAlerts = True
ActiveWorkbook.SaveAs Filename:=MyPath & "\" & FName, FileFormat:=xlCSV
ActiveWorkbook.Close savechanges:=False

End Sub

Any help would be greatly appreciated! This is for Excel 2003.

Last edited by mainemike : February 23rd 06 at 07:58 PM
 
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
Populating worksheet via a drop down list ! kuansheng Excel Worksheet Functions 4 February 14th 06 05:48 AM
breakdown a DB4 export into an excel worksheet Jim e boy Excel Worksheet Functions 2 March 10th 05 03:21 PM
Copy from worksheet to another x times Union70 Excel Discussion (Misc queries) 0 March 7th 05 09:03 PM
Worksheet Function - Find? DAA Excel Worksheet Functions 2 February 24th 05 04:15 PM
Weekly Transaction Processing Ralph Howarth Excel Worksheet Functions 4 January 19th 05 05:37 AM


All times are GMT +1. The time now is 01:15 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"